Good morning
I seem to be catching an error in PHP, ` Notice: Array to string conversion in C:\xampp\htdocs\sample\sample_page.php on line 80
I have an example multidimensional array as shown below
Array
(
[0] => Array
(
[id] => 3791671
[name] => photos
[permissions] => Array
(
[modify] => 1
[view] => 1
[collect] => 1
)
)
[1] => Array
(
[id] => 3791677
[name] => vehicle_incident_report_c_vehicle_details
[permissions] => Array
(
[modify] => 1
[view] => 1
[collect] => 1
)
)
[2] => Array
(
[id] => 3791680
[name] => vehicle_incident_report_c_vehicle_details_c_photos
[permissions] => Array
(
[modify] => 1
[view] => 1
[collect] => 1
)
)
[3] => Array
(
[id] => 3791689
[name] => inspection_photos
[permissions] => Array
(
[modify] => 1
[view] => 1
[collect] => 1
)
)
)
I am trying to format this array into a table format using the code below, but it gives me an array to string conversion error
// Transform data
$headers = [];
$rows = [];
$rowIdx = 0;
foreach ($array_example as $sample) {
foreach ($sample as $key => $value) {
if (!in_array($key, $headers)) {
$headers[] = $key;
}
$rows[$rowIdx][$key] = $value;
}
$rowIdx++;
}
// Display data
$html = "<table style='width:100%' id='table_id'><thead><tr>";
foreach ($headers as $header) {
$html .= "<th>$header</th>";
}
$html .= "</tr></thead><tbody>";
foreach ($rows as $row){
$html .= "<tr>";
foreach ($headers as $header) {
$html .= "<td>";
$html .= $row[$header]?? '';
$html .= "</td>";
}
$html .= "</tr>";
}
$html .= "</tr></tbody></table>";
echo $html;
Line 80 consists of
$html .= $row[$header]?? '';
Thank you in advance
`