How to structure multidimensional array with json

Asked

Viewed 88 times

0

Good night!! I have a json that returns in this format:

{rua: "A01", col: "01D", alt: "A"},{rua: "A01", col: "01D", alt: "B"},{rua: "A01", col: "01D", alt: "C"},{rua: "A01", col: "01D", alt: "D"}

But I need you to come back in this format:

{rua: "A01",end:{col: "01D",comp:{alt: "A",alt: "B",alt: "C",alt: "D"}

{rua: "A01",end:{col: "02D",comp:{alt: "A",alt: "B",alt: "C",alt: "D"}

My php is like this:

while ($query=mysqli_fetch_array($res)) {
    $array_end[] = array(
        'rua' => $query['rua'],
        'col' => $query['coluna'],
        'alt' => $query['altura'],
    );
}

Can someone help us? Thank you very much!

1 answer

0


for your while gets like this:

while ($query=mysqli_fetch_array($res)) {
$array_end[] = array(
    'rua' => $query['rua'],
    'end' => array(
         'col' => $query['coluna'],
         'comp' => array('alt' => $query['altura'])
       )
    );
}
  • Very good. Thank you!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.