3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ "one" => 1, "two" => 2, "three" => 3, "four" => 4 ]; while (($key = key($array)) !== null) { // check if the internal pointer points beyond the end of the elements list or the array is empty echo "$key => {$array[$key]}\n"; // display current key value pair if ($array[$key] < 3) { // an arbitrary condition echo "\t"; ++$array[$key]; // increment the current value } else { // current value is satisfactory echo "\t(advance pointer)\n"; next($array); // move pointer } }

preferences:
31.16 ms | 405 KiB | 5 Q