Example 1 — Step Through an Array
This example starts at the first element and moves forward twice.
<?php
$colors = ["red", "green", "blue"];
echo current($colors), PHP_EOL;
echo next($colors), PHP_EOL;
echo next($colors), PHP_EOL; How It Works
- The pointer starts on the first element, so current() returns "red".
- The first next() moves to the second element and returns "green".
- The second next() moves to the third element and returns "blue".
- Each echo prints the value that the pointer is now on.

