What is the purpose of using Modulo in PHP when displaying data from a SQL database in alternating columns?

When displaying data from a SQL database in alternating columns, using Modulo in PHP can help to determine whether the current iteration of the loop is an even or odd number. This can be useful for styling purposes, such as applying different CSS classes to alternating columns to create a visually appealing layout.

<?php
// Assuming $results is an array of data fetched from the SQL database

foreach ($results as $key => $result) {
    if ($key % 2 == 0) {
        // Display data in even column
        echo '<div class="even-column">' . $result['column_name'] . '</div>';
    } else {
        // Display data in odd column
        echo '<div class="odd-column">' . $result['column_name'] . '</div>';
    }
}
?>