How can a 3-dimensional array be structured efficiently in PHP for displaying SQL results in tabular form?

When displaying SQL results in tabular form, a 3-dimensional array can be structured efficiently by using nested loops to iterate through the data and organize it into rows and columns. Each row in the SQL results can be represented as an array, with each column value stored as a key-value pair. The outermost array would then hold all the rows, creating a structure that can easily be looped through to generate the tabular display.

// Assuming $sqlResults is the array containing the SQL results

echo '<table>';
foreach ($sqlResults as $row) {
    echo '<tr>';
    foreach ($row as $key => $value) {
        echo '<td>' . $value . '</td>';
    }
    echo '</tr>';
}
echo '</table>';