What is the purpose of using modulo in the context of iterating through an array in PHP?

When iterating through an array in PHP, using modulo can help ensure that the index stays within the bounds of the array. This is particularly useful when you want to cycle through the array repeatedly without going out of bounds.

$array = [1, 2, 3, 4, 5];
$length = count($array);

for ($i = 0; $i < 10; $i++) {
    $index = $i % $length;
    echo $array[$index] . "\n";
}