3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $a = array(1, 2, 3, 4, 5, 6, 7, 8, 9); reset ($a); foreach ($a as $v) { echo('Array points to: ' . current($a) . ' foreach() is at element: ' . $v . '\n'); } echo('After loop array points to: ' . current($a));
based on L9mhr
Output for 7.0.28 - 7.3.0rc3
Array points to: 1 foreach() is at element: 1\nArray points to: 1 foreach() is at element: 2\nArray points to: 1 foreach() is at element: 3\nArray points to: 1 foreach() is at element: 4\nArray points to: 1 foreach() is at element: 5\nArray points to: 1 foreach() is at element: 6\nArray points to: 1 foreach() is at element: 7\nArray points to: 1 foreach() is at element: 8\nArray points to: 1 foreach() is at element: 9\nAfter loop array points to: 1
Output for 5.6.38
Array points to: 2 foreach() is at element: 1\nArray points to: 2 foreach() is at element: 2\nArray points to: 2 foreach() is at element: 3\nArray points to: 2 foreach() is at element: 4\nArray points to: 2 foreach() is at element: 5\nArray points to: 2 foreach() is at element: 6\nArray points to: 2 foreach() is at element: 7\nArray points to: 2 foreach() is at element: 8\nArray points to: 2 foreach() is at element: 9\nAfter loop array points to: 2