Example 1 — Read the Value at the Pointer
pos() reads the value, and next() moves the pointer so that pos() gives a different value.
<?php
$letters = ["x", "y", "z"];
echo pos($letters), PHP_EOL;
next($letters);
echo pos($letters), PHP_EOL; How It Works
- The pointer starts on the first element, so pos() returns "x".
- pos() does not move the pointer.
- next() moves the pointer forward by one element.
- pos() now returns "y".

