jonaofarc Posted April 6, 2008 Share Posted April 6, 2008 Guys Iam freaking out ... basically Iam using this script that returns a list of zip codes in a certain radius... so the array that it returns looks like this... Array ( [97214] => 0 [97293] => 0.48 [97232] => 0.69 [97242] => 0.84 [97258] => 1.45 [97204] => 1.45 [97255] => 1.61 [97253] => 1.61 [97208] => 1.61 [97228] => 1.61 [97240] => 1.61 ) However I need to be able to just have the zip code alone so I can use it in sql by using the IN statement to return a list of place in X amount of Miles so essential I need this array in this format 97214, 97293, 97232, 97242 and so on.... Thank you guys so much in advance! Link to comment https://forums.phpfreaks.com/topic/99813-implode-a-two-dimensional-array/ Share on other sites More sharing options...
doni49 Posted April 6, 2008 Share Posted April 6, 2008 1) That's not a 2d array--that's 1d but the keys are not integer based. 2) What you want to do is get an array of the keys and implode them. Assuming that your array is called $zip1: $zip2 = array_keys($zip1); $zipstring = implode(",", $zip2); Link to comment https://forums.phpfreaks.com/topic/99813-implode-a-two-dimensional-array/#findComment-510479 Share on other sites More sharing options...
doni49 Posted April 6, 2008 Share Posted April 6, 2008 I thought maybe I should further explain point number 1 from above. By default, PHP uses integers for the array keys. But you can use strings if you want--it can be very useful. These all have the same effect--they will all produce a 1d array with integer based keys numbered from 0 to 1: $ar1[]="test"; $ar1[]="test again"; $ar2[0]="test"; $ar2[1]="test again"; $ar3 = array("test", "test again"); While the following will create string based key names: $ar4['First'] = 'Test'; $ar4['Second']='Test again'; $ar5=array('First'=>'Test', 'Second'=>'Test again'); Now the following is an example of a 2d array: $ar6[0][0]="Test"; $ar6[0][1]="Testing"; $ar6[1][0]="keep going"; $ar6[1][1]="still going"; Link to comment https://forums.phpfreaks.com/topic/99813-implode-a-two-dimensional-array/#findComment-510491 Share on other sites More sharing options...
jonaofarc Posted April 7, 2008 Author Share Posted April 7, 2008 thank you Link to comment https://forums.phpfreaks.com/topic/99813-implode-a-two-dimensional-array/#findComment-511257 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.