I need to create a table where the week numbers are the columns and the employees are the first column, like this:
But from an array in php like the following:
/**
* [$key Año]
* [$key2 Semana]
* [$key3 Empleado]
* [$value3 Total horas]
*/
echo '<table class="table table-condensed table-hover">';
foreach ($weeksT as $key => $value) {
foreach ($value as $key2 => $value2) {
echo '<td>'.$key2.'</td>';
foreach ($value2 as $key3 => $value3) {
//echo $key2 . ' | ' . getNameEmp($key3) . ' - ' . $value3 . '<br>';
echo '<tr>';
echo '<td>'.$key3.'</td>';
echo '</tr>';
}
}
}
echo '</table>';`
Any idea how to accommodate it?
Edited: fix content:
Array
(
[2018] => Array
(
[08] => Array
(
[40] => 68
)
[09] => Array
(
[11] => 50
[18] => 60
[28] => 50
[32] => 68
[34] => 60
)
[10] => Array
(
[11] => 60
[18] => 60
[24] => 58
[28] => 60
[31] => 60
[32] => 60
[37] => 60
[38] => 48
)
[11] => Array
(
[11] => 58
[18] => 35
[24] => 68
[28] => 35
[32] => 68
[37] => 58
[38] => 50
[43] => 34.25
)
If I understood your data structure correctly, here is a possible solution.
I use two years and generate a table for each year.
Code with a possible solution
Result:
In a more realistic system , the employees who go to work each week of the year are not always the same, and there may also be weeks when no employee works. Then the table will probably have empty cells and a "row of weeks" with the weeks in which you work and an "column of employees" with the employees who work in at least one of those weeks, and it may also be several or all.
The result would be something like this, for the table of a certain year:
I am going to put a complete example (I have adjusted the arrays with the data for the new assumption):
Result: