Example 1 — Read the Key at the Pointer
This example reads a key, moves the pointer with next(), and reads the key again.
<?php
$scores = ["x" => 1, "y" => 2];
echo key($scores), PHP_EOL;
next($scores);
echo key($scores), PHP_EOL; How It Works
- A new array starts with the pointer on its first element, so key() returns "x".
- next() moves the pointer forward by one element.
- The pointer now points at the second element.
- key() returns "y", the key of that element.

