0
Good evening guys, I’m having an immense difficulty regarding arrays...
I have the following array:
array(6) {
[0]=>
array(1) {
["cep"]=>
array(2) {
[0]=>
string(8) "15070650"
[1]=>
string(8) "03216040"
}
}
[1]=>
array(1) {
["endereco"]=>
array(2) {
[0]=>
string(21) "Avenida Murchid Homsi"
[1]=>
string(17) "Rua São Raimundo"
}
}
[2]=>
array(1) {
["numero"]=>
array(2) {
[0]=>
string(3) "275"
[1]=>
string(3) "275"
}
}
[3]=>
array(1) {
["bairro"]=>
array(2) {
[0]=>
string(41) "Parque Residencial Comendador Mancor Daud"
[1]=>
string(16) "Vila Califórnia"
}
}
[4]=>
array(1) {
["cidade"]=>
array(2) {
[0]=>
string(23) "São José do Rio Preto"
[1]=>
string(10) "São Paulo"
}
}
[5]=>
array(1) {
["uf"]=>
array(2) {
[0]=>
string(2) "SP"
[1]=>
string(2) "SP"
}
}
}
example: suppose I need to pick up the zip code, address, number, neighborhood, city, Uf line for example to insert into the bank.
example:
line 1: 15070650, Avenida Murchid Homsi, 275, Parque Residencial Comendador Mancor Daud, São José do Rio Preto, SP
line 2: 03216040, Rua São Raimundo, 275, Vila California, São Paulo, SP
I tried it this way:
for ($i = 0; $i < count($dados_endereco); $i++) {
for ($j = 0; $j < count($dados_endereco[$i]); $j++) {
for ($k = 0; $k < count($dados_endereco[$i][$j]); $k++) {
var_dump($dados_endereco[$i][$j][$k]);
}
}
}
but you didn’t call me right back...
in JSON:
[
{
"cep":[
"15070650",
"03216040"
]
},
{
"endereco":[
"Avenida Murchid Homsi",
"Rua S\u00e3o Raimundo"
]
},
{
"numero":[
"275",
"275"
]
},
{
"bairro":[
"Parque Residencial Comendador Mancor Daud",
"Vila Calif\u00f3rnia"
]
},
{
"cidade":[
"S\u00e3o Jos\u00e9 do Rio Preto",
"S\u00e3o Paulo"
]
},
{
"uf":[
"SP",
"SP"
]
}
]
Thanks for your help. If the question is duplicated, please put the question link in the comments.
To work with Arrays, give preference to
foreach
, as it facilitates and can manipulate both the key and the value.– rbz
Rbz first thanks for the tip. With foreach how do I achieve these values? I prefer with for because I couldn’t get by foreach.
– Joao Pedro
Can you put the array in string format? The way it is I can’t test.
– rbz
Rbz, no, this data comes from a front input array.. = /, I’ll post it as json for you
– Joao Pedro
RBZ, posted in json
– Joao Pedro
worked out!!! thank you very much! I will understand this code now. Thanks very much!
– Joao Pedro
Time you take a break, I’ll edit and explain every step. ;)
– rbz