How can nested loops be used to optimize the display of specific columns in a table based on conditions in PHP?

Nested loops can be used to iterate through rows and columns of a table in PHP. By using nested loops, you can check specific conditions for each column and only display the columns that meet those conditions. This can help optimize the display of specific columns in a table based on certain criteria.

<?php

// Sample table data
$tableData = [
    ['Name', 'Age', 'City'],
    ['John', 25, 'New York'],
    ['Alice', 30, 'Los Angeles'],
    ['Bob', 22, 'Chicago']
];

// Display only columns where the age is greater than 25
foreach ($tableData as $row) {
    foreach ($row as $key => $value) {
        if ($row[1] > 25) {
            echo $value . " ";
        }
    }
    echo "<br>";
}

?>