shadiadiph Posted November 2, 2009 Share Posted November 2, 2009 I have been building a script all week using the maxminds database. Problem I have now is to get down to the city codes they are numbered 1 2 3 4 etc by region code but the regioncodes arrays are retuning 01 02 03 04 how can I strip that annoying zero off the regioncode probabaly very easy but I am just frustrated. another silly question how do i get an array from this instead of one value I know i can echo and get a list displaye but I want to make an array out of all the cities for the country I uploaded the csv to mysql so I am calling it by while($row=mysql_fetch_array($rgetcity)){ $citys = $row["city"]; Link to comment https://forums.phpfreaks.com/topic/179950-solved-stripping-zeros-from-arrays/ Share on other sites More sharing options...
seanlim Posted November 2, 2009 Share Posted November 2, 2009 $cities = array(); while($row=mysql_fetch_array($rgetcity))} $cities[] = ltrim($row['city'], "0"); } Link to comment https://forums.phpfreaks.com/topic/179950-solved-stripping-zeros-from-arrays/#findComment-949281 Share on other sites More sharing options...
JAY6390 Posted November 2, 2009 Share Posted November 2, 2009 Assuming your code is in a field named 'code' use the following which will store all city information into the citys var $citys = array(); while($row=mysql_fetch_array($rgetcity)){ $row['code'] = intval($row['code']); $citys[$row['code']] = $row; } For example if you wanted the city with an id of 4 after the loop, use echo $citys[4]['city']; Link to comment https://forums.phpfreaks.com/topic/179950-solved-stripping-zeros-from-arrays/#findComment-949283 Share on other sites More sharing options...
shadiadiph Posted November 3, 2009 Author Share Posted November 3, 2009 thanks for the input guys but the first way kind of worked the second produced a horrible looking array so I ended up using the following as an example. while($row=mysql_fetch_array($rgetcountrycodes)){ $countrycodes[]= $row['countrycode']; $countrys[]= $row['country']; } $newcountryinfo = array_combine($countrycodes, $countrys); [code] produced and array [AF] => Afghanistan etc Link to comment https://forums.phpfreaks.com/topic/179950-solved-stripping-zeros-from-arrays/#findComment-950589 Share on other sites More sharing options...
JAY6390 Posted November 4, 2009 Share Posted November 4, 2009 Surely it would have been easier to just use this if that's all you were wanting to extract $newcountryinfo = array(); while($row = mysql_fetch_assoc($rgetcountrycodes)) { $newcountryinfo[$row['countrycode']] = $row['country']; } Link to comment https://forums.phpfreaks.com/topic/179950-solved-stripping-zeros-from-arrays/#findComment-950668 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.