I have a multidimensional array, and I want to show this array in tabular form like
+------+-----+--------+-------+-------+
| Name | red | yellow | green | white |
+------+-----+--------+-------+-------+
| abc | 8 | 2 | 4 | 0 |
| xyz | 2 | 8 | 0 | 0 |
+------+-----+--------+-------+-------+
The following is the array that I've
[0] => array(
'label'=> 'red',
[value] => Array
(
[0] => array
(
[count] => 47
[firstname] => Syst
)
[1] => array
(
[count] => 2
[firstname] => xyz
)
[2] => array
(
[count] => 8
[firstname] => abc
)
)
[1] => array(
'label'=> 'yellow',
[value] => Array
(
[0] => array
(
[count] => 4
[firstname] => dim
)
[1] => array
(
[count] => 2
[firstname] => abc
)
[2] => array
(
[count] => 8
[firstname] => xyz
)
)
and so on I have tired below code but I don't know whats the problem with code.
foreach($rows as $row)
{
echo '<th>'.$row->label.'</th></tr>';
$i = 1;
$final = [];
foreach($row->value as $v){
$temp = [];
$temp[$v->firstname.' '.$v->lastname] = [];
$output = findKey($final, $v->firstname.' '.$v->lastname);
if($output){
$temp[$v->firstname.' '.$v->lastname]['count'] = $v->count ;
$temp[$v->firstname.' '.$v->lastname][$row->label.'_'.$row->color] = $v->count ;
}
array_push($final,$temp);
}
}
print_r($rows); //die;