How can PHP be used to display data in columns within an HTML table?

To display data in columns within an HTML table using PHP, you can use a loop to iterate through your data and output each item within a table row. By organizing your data in columns within the loop, you can ensure that each item is displayed in the correct column of the table.

<table>
    <tr>
        <th>Column 1</th>
        <th>Column 2</th>
        <th>Column 3</th>
    </tr>
    <?php
    // Your data array
    $data = array(
        array('Item 1', 'Item 2', 'Item 3'),
        array('Item 4', 'Item 5', 'Item 6'),
        array('Item 7', 'Item 8', 'Item 9')
    );

    // Loop through the data and display in columns
    foreach ($data as $row) {
        echo '<tr>';
        foreach ($row as $item) {
            echo '<td>' . $item . '</td>';
        }
        echo '</tr>';
    }
    ?>
</table>