I am given an array of arrays, to simplify each array has
[0] => Array
(
[target_id]
[target_date]
[intensity_id]
[target_intensity]
)
[1] => Array
(
[target_id]
[target_date]
[intensity_id]
[target_intensity]
)
example data (the original array is an assoc array)
target_id target_date intensity_id target_intensity
1829 2017-06-23 2 good
2013 2017-05-22 1 bad
2024 2017-05-18 1 bad
2029 2017-05-14 1 bad
2032 2017-05-10 3 bad
2329 2017-03-23 2 good
2629 2017-03-12 3 excellent
2830 2017-02-03 2 good
3829 2017-02-23 2 good
4029 2017-02-18 1 bad
3829 2017-01-23 2 good
3829 2016-12-12 3 excellent
3829 2016-12-23 2 good
now i need to echo this data as input for a google stacked bar graph.
So I need to get the sum (number of times an intensity appears in a month) of target_intensity by month, like so
date bad good excellent
2016 dec 0 1 1
2017 jan 0 1 0
2017 feb 1 2 0
2017 mrt 0 1 1
2017 may 3 0 1
2017 jun 0 1 0
and here I am stuck
$tmpArray = array(
array('target_id' => 1829, 'target_date' => '2017-06-23', 'intensity_id'=>2, 'target_intensity'=>'good'),
array('target_id' => 2013, 'target_date' => '2017-05-22', 'intensity_id'=>1, 'target_intensity'=>'bad'),
array('target_id' => 2024, 'target_date' => '2017-05-18', 'intensity_id'=>1, 'target_intensity'=>'bad'),
array('target_id' => 2029, 'target_date' => '2017-05-14', 'intensity_id'=>1, 'target_intensity'=>'bad'),
array('target_id' => 2032, 'target_date' => '2017-05-10', 'intensity_id'=>3, 'target_intensity'=>'bad'),
array('target_id' => 2329, 'target_date' => '2017-03-23', 'intensity_id'=>2, 'target_intensity'=>'good'),
array('target_id' => 2629, 'target_date' => '2017-03-12', 'intensity_id'=>3, 'target_intensity'=>'excellent'),
array('target_id' => 2830, 'target_date' => '2017-02-03', 'intensity_id'=>2, 'target_intensity'=>'good'),
array('target_id' => 3829, 'target_date' => '2017-02-23', 'intensity_id'=>2, 'target_intensity'=>'good'),
array('target_id' => 4029, 'target_date' => '2017-02-18', 'intensity_id'=>1, 'target_intensity'=>'bad'),
array('target_id' => 4039, 'target_date' => '2017-01-23', 'intensity_id'=>2, 'target_intensity'=>'good'),
array('target_id' => 4049, 'target_date' => '2016-12-12', 'intensity_id'=>3, 'target_intensity'=>'excellent'),
array('target_id' => 4056, 'target_date' => '2016-12-23', 'intensity_id'=>2, 'target_intensity'=>'good')
);
//echo $tmpArray[3]['target_date'];
//exit();
// should i first loop and order by month and then
//should i create 3 tmp arrays for bad, good and excellent
foreach ($tmpArray as $key => $values) {
echo $values['target_date'] . '<br/>';
//print_r ($values).'<br/>';
foreach ($values as $key => $value) {
// echo '<pre>';
echo $key . ' - ' . $value . '<br/>';
// echo '</pre>';
}
echo '<hr/>';
}
Any help appreciated
2016has onlyexcellentandgoodintensity, so why did you specifybad: 1in your output for2016 dec?