How can nested foreach loops be utilized effectively in PHP to display specific array values in separate cells of a table?

Nested foreach loops can be utilized effectively in PHP to display specific array values in separate cells of a table by iterating through the outer array and then iterating through the inner array within each iteration of the outer loop. This allows for precise control over which values are displayed in each cell of the table.

<?php
// Sample nested array
$nestedArray = array(
    array("John", "Doe", "30"),
    array("Jane", "Smith", "25"),
    array("Mike", "Johnson", "35")
);

// Displaying the nested array values in a table
echo "<table border='1'>";
foreach ($nestedArray as $innerArray) {
    echo "<tr>";
    foreach ($innerArray as $value) {
        echo "<td>$value</td>";
    }
    echo "</tr>";
}
echo "</table>";
?>