manipulating an array to mount the grid

0

I have an array in php and I need to get the values together so I can put them in a table> phtml

Follow jsonArray You will always have these five types of transportation.

I could not do much to leave here what has already been done, the only thing I have is

public function relatorio($dtInicio, $dtFinal) {
        $dbControleVeiculos = new \Db\Fisc\ControleVeiculos();
        $original = iterator_to_array($dbControleVeiculos->getResumoControleVeiculos($dtInicio, $dtFinal));

        $result = array();
        foreach ($original as $data) {
            $id = $data['nome'];
            if (isset($result[$id])) {
                $result[$id][] = $data;
            } else {
                $result[$id] = array($data);
            }
        }

        return $result;
        // return 
    }

My goal is to stay that way.

    
asked by anonymous 11.07.2018 / 20:25

1 answer

0

If it is the sum index, you could do so:

if (isset($result[$id])) {
     $result[$id][] = $data;
     $result[$id]['sum_total] += $data['sum']
} else {
     $result[$id] = array($data);
     $result[$id]['sum_total] += $data['sum']
}

But it would be more organized, if given groupBy by name. Then I could make the foreach more complete +/- like this:

foreach($original as $nome => $data) {...}

Where this name would be an index with the value of your name in question

    
13.07.2018 / 21:36