What is the purpose of using the modulo operator in PHP when working with arrays and loops?

When working with arrays and loops in PHP, using the modulo operator (%) can be helpful for tasks such as evenly distributing elements or performing actions at specific intervals. For example, you can use the modulo operator to determine if the current iteration in a loop is a multiple of a certain number, allowing you to perform a certain action only on those iterations.

// Example of using the modulo operator in a loop
$array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
$interval = 3;

foreach ($array as $key => $value) {
    if ($key % $interval == 0) {
        echo "Element at index $key is: $value\n";
    }
}