I want to create a separate array in groups by date of the result of a query made in DB
example:
// [...]
$sql = $this->db->query($query) or die (sprintf("Falha: %s", $this->db->error()));
if ($sql->num_rows) {
while ($row = $sql->fetch_object()) {
$data[] = $row;
}
}
// [...]
Sample Test:
$data[] = array(
'data' => '2015-02-05',
'refer' => 'X741852',
'favorecido' => 'MARIA',
'debito' => '2.500'
);
$data[] = array(
'data' => '2015-02-05',
'refer' => 'B890656',
'favorecido' => 'EDUARDA',
'debito' => '500'
);
$data[] = array(
'data' => '2015-02-18',
'refer' => 'CK546045',
'favorecido' => 'JOAO',
'debito' => '42.050'
);
$data[] = array(
'data' => '2014-06-09',
'refer' => 'FE55852',
'favorecido' => 'CHARLES',
'debito' => '28.500'
);
$data[] = array(
'data' => '2014-06-09',
'refer' => 'X741852',
'favorecido' => 'VIVIANE',
'debito' => '74.2500'
);
output:
Array
(
[0] => Array
(
[data] => 2015-02-05
[refer] => X741852
[favorecido] => MARIA
[debito] => 2.500
)
[1] => Array
(
[data] => 2015-02-05
[refer] => B890656
[favorecido] => EDUARDA
[debito] => 500
)
[2] => Array
(
[data] => 2015-02-18
[refer] => CK546045
[favorecido] => JOAO
[debito] => 42.050
)
[3] => Array
(
[data] => 2014-06-09
[refer] => FE55852
[favorecido] => CHARLES
[debito] => 28.500
)
[4] => Array
(
[data] => 2014-06-09
[refer] => X741852
[favorecido] => VIVIANE
[debito] => 74.2500
)
)
Intended Result:
Array
(
[2015-02-05] => Array
(
[0] => Array
(
[data] => 2015-02-05
[refer] => X741852
[favorecido] => MARIA
[debito] => 2.500
)
[1] => Array
(
[data] => 2015-02-05
[refer] => B890656
[favorecido] => EDUARDA
[debito] => 500
)
)
[2015-02-18] => Array
(
[2] => Array
(
[data] => 2015-02-18
[refer] => CK546045
[favorecido] => JOAO
[debito] => 42.050
)
)
[2014-06-09] => Array
(
[3] => Array
(
[data] => 2014-06-09
[refer] => FE55852
[favorecido] => CHARLES
[debito] => 28.500
)
[4] => Array
(
[data] => 2014-06-09
[refer] => X741852
[favorecido] => VIVIANE
[debito] => 74.2500
)
)
)