Jump to content

[SOLVED] stripping zeros from arrays


shadiadiph

Recommended Posts

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

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'];

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.