$colors = ["red", "green", "blue"]; echo "The current color is: " . current($colors) . "
"; echo "The next color is: " . next($colors) . "
"; echo "The current color is: " . current($colors) . "
"; echo "The previous color is: " . prev($colors) . "
"; echo "The current color is: " . current($colors) . "
";
The current color is: red The next color is: green The current color is: green The previous color is: red The current color is: red
$array = new SplFixedArray(3); $array[0] = "cat"; $array[1] = "dog"; $array[2] = "bird"; echo "The current animal is: " . $array->current() . "
"; $array->next(); echo "The next animal is: " . $array->current() . "
";
The current animal is: cat The next animal is: dogThe getCurrent() method belongs to the PHP Standard Library.