How to structure multidimensional array with json

0

Good evening !!! 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 return 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 looks like this:

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

Can anyone help? Many thanks!

    
asked by anonymous 28.02.2018 / 01:46

1 answer

0

for your while looks like this:

while ($query=mysqli_fetch_array($res)) {
$array_end[] = array(
    'rua' => $query['rua'],
    'end' => array(
         'col' => $query['coluna'],
         'comp' => array('alt' => $query['altura'])
       )
    );
}
    
28.02.2018 / 02:36