I have a data in the below format
$data =
Array
(
[0] => Array
(
[cdt] => 2016-01-01
[name] => Harish
[hour] => 8.5
)
[1] => Array
(
[cdt] => 2016-01-01
[name] => Preeti
[hour] => 8
)
[2] => Array
(
[cdt] => 2016-01-01
[name] => Sunit
[hour] => 9
)
[3] => Array
(
[cdt] => 2016-01-01
[name] => Prabhakar
[hour] => 8
)
[4] => Array
(
[cdt] => 2016-01-02
[name] => Prabhakar
[hour] => 2
)
[5] => Array
(
[cdt] => 2016-01-04
[name] => Preeti
[hour] => 8
)
[6] => Array
(
[cdt] => 2016-01-04
[name] => Sunit
[hour] => 9
)
[7] => Array
(
[cdt] => 2016-01-04
[name] => Harish
[hour] => 9.5
)
[8] => Array
(
[cdt] => 2016-01-04
[name] => Prabhakar
[hour] => 10
)
[9] => Array
(
[cdt] => 2016-01-05
[name] => Preeti
[hour] => 10
)
[10] => Array
(
[cdt] => 2016-01-05
[name] => Sunit
[hour] => 8
)
[11] => Array
(
[cdt] => 2016-01-05
[name] => Harish
[hour] => 9
)
[12] => Array
(
[cdt] => 2016-01-05
[name] => Prabhakar
[hour] => 9
)
)
I want it to be in this format
Array
(
[0] => 2016-01-01, Harish: 8.5, Preeti: 8, Sunit: 9, Prabhakar: 8
[1] => 2016-01-02, Prabhakar: 2
[2] => 2016-01-04, Preeti: 8, Sunit: 9, Harish: 9.5, Prabhakar: 10
[3] => 2016-01-05, Preeti: 10, Sunit: 8, Harish: 9, Prabhakar: 9
)
I have tried some loops but those were not helpful. I am not good in foreach loop, but I have a doubt that it will solve the problem.
Below is the code that I have tried
$k=0;
for($i = 0; $i < sizeOf($uniqueDates); $i++)
{
$chartData[$i] = 'y: '.$data[$i]['cdt'].', ';
for($j = $k; $j < Sizeof($data); $j++)
{
if($uniqueDates[$i] == $data[$j]['cdt'])
{
$chartData[$i] .= $data[$j]['name'].': '.$data[$j]['hour'].', ';
}
}
$k++;
}
In $uniqueDates I have taken all the unique dates and $data is the array that contains the data in the above format.