Reputation: 1030
I have the code below that shows all the postal codes in São Paulo / Brazil. The thing here is that it's not showing the correct number, it is showing a completely different number.
How may I fix it to show the number in the $SP
array?
$SP = ['São Paulo 1' => [01000, 05999], 'São Paulo 2' => [08000, 08499], 'Osasco' => [06000, 06299], 'Carapicuiba' => [06300, 06399], 'Barueri' => [06400, 06499], 'Santana do Parnaíba' => [06500, 06549], 'Pirapora Do Bom Jesus' => [06550, 06599], 'Jandira' => [06600, 06649], 'Itapevi' => [06650, 06699], 'Cotia' => [06700, 06729], 'Vargem Grande Paulista' => [06730, 06749], 'Taboão Da Serra' => [06750, 06799], 'Embu' => [06800, 06849], 'Itapecerica Da Serra' => [06850, 06889], 'São Lourenço Da Serra' => [06890, 06899], 'Embu-Guaçu' => [06900, 06930], 'Juquitiba' => [06950, 06999], 'Guarulhos' => [07000, 07399], 'Arujá' => [07400, 07499], 'Santa Isabel' => [07500, 07599], 'Mairiporã' => [07600, 07699], 'Caieiras' => [07700, 07749], 'Cajamar' => [07750, 07769], 'Franco da Rocha' => [07800, 07899], 'Francisco Morato' => [07900, 07999], 'Ferraz de Vasconcelos' => [08500, 08549], 'Poá' => [08550, 08569], 'Itaquaquecetuba' => [08570, 08599], 'Suzano' => [08600, 08699], 'Mogi das Cruzes' => [08700, 08899], 'Guararema' => [08900, 08939], 'Biritiba-Mirim' => [08940, 08969], 'Salesópolis' => [08970, 08979], 'Santo,ndré' => [09000, 09299], 'Mauá' => [09300, 09399], 'Ribeirão Pires' => [09400, 09449], 'Rio Grande da Serra' => [09450, 09499], 'São Caetano do Sul' => [09500, 09599], 'São Bernardo do Campo' => [09600, 09899], 'Diadema' => [09900, 09999], 'SP Litoral' => [11000, 11999], 'SP Interior' => [12000, 19999]];
foreach ($SP as $key => $value) {
echo $key . ': ';
var_dump($value);
echo '<BR>';
}
Results in:
São Paulo 1: array(2) { [0]=> int(512) [1]=> int(5) }
São Paulo 2: array(2) { [0]=> int(0) [1]=> int(0) }
Osasco: array(2) { [0]=> int(3072) [1]=> int(50) }
Carapicuiba: array(2) { [0]=> int(3264) [1]=> int(51) }
Barueri: array(2) { [0]=> int(3328) [1]=> int(52) }
...
Upvotes: 0
Views: 46
Reputation: 3039
Do not prefix the numbers with a 0, or encapsulate them in quotes (so PHP sees them as a string). Numbers beginning with zeroes are interpreted as octal values.
Proof. (I only changed the first three sub-arrays.) Details.
Upvotes: 1
Reputation: 3117
Invalid octal literal.
Try to remove "0" from the beginning of the numbers.
Upvotes: 1
Reputation: 99
5 digits length numbers starting with a 0 are not considered as decimal. If you want to keep the zero you have to use quotes : "01000"
Upvotes: 1