I have the following array:
Array
(
[0] => stdClass Object
(
[anomes] => 201601
[codreg] => 41
[nomreg] => PR
[codcin] => 1
[nomcin] => OUTROS
[valven] => 6835.7000
[qtdven] => 1078.8000
)
[1] => stdClass Object
(
[anomes] => 201601
[codreg] => 42
[nomreg] => SC
[codcin] => 1
[nomcin] => OUTROS
[valven] => 3129.0000
[qtdven] => 366.6200
)
[2] => stdClass Object
(
[anomes] => 201601
[codreg] => 42
[nomreg] => SC
[codcin] => 2
[nomcin] => PECAS
[valven] => 346.9100
[qtdven] => 73.6600
)
)
I would like to group it by codreg, I implemented the following:
$saida = array();
foreach ($dadf513 as $row) {
if(!isset($saida[$row->nomreg])) {
$saida[$row->nomreg] = array(floatval($row->valven));
} else {
array_push($saida[$row->nomreg], floatval($row->valven));
}
$arrayFinal[$row->nomreg] = [
'name' => $row->nomreg,
'data' => $saida[$row->nomreg]
];
}
print_r($arrayFinal);
and target the result:
Array
(
[PR] => Array
(
[name] => PR
[data] => Array
(
[0] => 6835.7
)
)
[SC] => Array
(
[name] => SC
[data] => Array
(
[0] => 3129
[1] => 346.91
)
)
)
So far beauty, my question is as follows, how to pass the value 0 on [date], when there is no value? To stay as follows:
Array
(
[PR] => Array
(
[name] => PR
[data] => Array
(
[0] => 6835.7
[1] => 0
)
)
[SC] => Array
(
[name] => SC
[data] => Array
(
[0] => 3129
[1] => 346.91
)
)
)