How can conditional statements be used effectively in PHP to handle different scenarios when generating output tables?

When generating output tables in PHP, conditional statements can be used effectively to handle different scenarios based on the data being displayed. For example, you can use conditional statements to format specific cells differently or display different content based on certain conditions. This allows for more dynamic and customized output tables.

<table>
    <tr>
        <th>Name</th>
        <th>Age</th>
    </tr>
    <?php
    $users = [
        ['name' => 'John', 'age' => 25],
        ['name' => 'Jane', 'age' => 30],
        ['name' => 'Alice', 'age' => 22]
    ];
    
    foreach($users as $user){
        echo "<tr>";
        echo "<td>{$user['name']}</td>";
        if($user['age'] < 25){
            echo "<td style='color: red;'>{$user['age']}</td>";
        } else {
            echo "<td>{$user['age']}</td>";
        }
        echo "</tr>";
    }
    ?>
</table>