How can a PHP script be modified to display data in three columns instead of one?

To display data in three columns instead of one, you can modify the PHP script to use a loop to iterate through the data and output it in a structure that creates three columns. You can achieve this by calculating the number of items per column and using CSS to style the columns accordingly.

<?php
// Sample data array
$data = array("Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10");

// Calculate number of items per column
$items_per_column = ceil(count($data) / 3);

// Output data in three columns
echo '<div style="display: flex;">';
for ($i = 0; $i < 3; $i++) {
    echo '<div style="flex: 1;">';
    for ($j = $i * $items_per_column; $j < min(($i + 1) * $items_per_column, count($data)); $j++) {
        echo $data[$j] . '<br>';
    }
    echo '</div>';
}
echo '</div>';
?>