timmah1 Posted March 12, 2012 Share Posted March 12, 2012 Probably a simple solution, just one I'm not sure how to do it. I need the array to print out like this array( 'name'=>'Store 1', 'address'=>'LA1' ), Right now, I got it to look like this Thanks in advance Array ( [name] => 'Albertville Farmers Market', [address] => '116 Main Street Albertville, Alabama 35950' ) , Array ( [name] => 'Alexander City Downtown Market', [address] => 'Braod Street Alexander City, Alabama 35010' ) , How can I go about accomplishing this? Here is my code $stores = array('name'=>"'$MktName',",'address'=>"'$address'"); echo "<pre>"; print_r($stores); echo "</pre>"; Quote Link to comment https://forums.phpfreaks.com/topic/258771-array-print/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 12, 2012 Share Posted March 12, 2012 var_export Quote Link to comment https://forums.phpfreaks.com/topic/258771-array-print/#findComment-1326560 Share on other sites More sharing options...
timmah1 Posted March 12, 2012 Author Share Posted March 12, 2012 var_export Thank you but how can I get a comma after the closing bracket? array( 'name'=>'Store 1', 'address'=>'LA1' ), <------- Quote Link to comment https://forums.phpfreaks.com/topic/258771-array-print/#findComment-1326562 Share on other sites More sharing options...
PFMaBiSmAd Posted March 12, 2012 Share Posted March 12, 2012 You would echo/concatenate/implode it (take your pick depending on what you are trying to accomplish.) Why do you want to echo an array like this? There is little practical use to it. Quote Link to comment https://forums.phpfreaks.com/topic/258771-array-print/#findComment-1326577 Share on other sites More sharing options...
timmah1 Posted March 12, 2012 Author Share Posted March 12, 2012 There is little practical use to it. You're right. I'm trying to work with this geo coding script, and trying to add multiple items into the database at once, instead of one at a time, and it wanted the array's like that. I figured out a way around it, thank you for your help. Maybe you can help me out with this I'm getting this error when trying to import Fatal error: Cannot use string offset as an array in /home/redneck/public_html/markets/admin/import.php on line 44 This is the code $stores = array( array ( 'name'=>'Albertville Farmers Market', 'address'=>'116 Main Street Albertville Alabama 35950' ), array ( 'name'=>'Alexander City Downtown Market', 'address'=>'Braod Street Alexander City Alabama 35010' ), ); // connect to database $db = db_connect(); $errors = array(); // import each store foreach($stores as $k=>$v) { // geocode address // $tmp = file_get_contents("http://maps.googleapis.com/maps/api/geo?q=".urlencode($v['address'])."&gl={$region}&output=xml&js?key={$google_api_key}&sensor=false"); $tmp = file_get_contents("http://maps.google.com/maps/geo?q=".urlencode($v['address'])."&gl={$region}&output=xml&sensor=false&key={$google_api_key}"); $xml = XML2Array($tmp); // lookup successful if($xml['Response']['Status']['code']=='200') { // get latitude/longitude $coords = explode(',', $xml['Response']['Placemark']['Point']['coordinates']); <---- LINE 44 // if valid if(isset($coords[0]) && isset($coords[1])) { // build data $data = array( 'name'=>$v['name'], 'address'=>$v['address'], 'latitude'=>$coords[1], 'longitude'=>$coords[0] ); // insert store if( !$db->insert('stores',$data) ) { $errors[] = 'There was a problem inserting a store: '.$v['name'].', '.$v['address']; } } } else { $errors[] = 'Address Not Found: '.$v['name'].', '.$v['address']; } } Quote Link to comment https://forums.phpfreaks.com/topic/258771-array-print/#findComment-1326580 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.