3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 'a', 'b', 'c', ]; function insertWhileIteratingForward($arr) { foreach ($arr as $index => $value) { if ($value === 'a' || $value === 'c') { array_splice($arr, $index, 0, ['new', 'new', 'new', 'new', 'new']); } } return $arr; } function insertWhileIteratingBackward($arr) { for ($index = count($arr) - 1; $index >= 0; --$index) { $value = $arr[$index]; if ($value === 'a' || $value === 'c') { array_splice($arr, $index, 0, ['new', 'new', 'new', 'new', 'new']); } } return $arr; } var_dump(insertWhileIteratingForward($array)); var_dump(insertWhileIteratingBackward($array));
Output for git.master_jit, git.master
array(13) { [0]=> string(3) "new" [1]=> string(3) "new" [2]=> string(3) "new" [3]=> string(3) "new" [4]=> string(3) "new" [5]=> string(3) "new" [6]=> string(3) "new" [7]=> string(3) "new" [8]=> string(3) "new" [9]=> string(3) "new" [10]=> string(1) "a" [11]=> string(1) "b" [12]=> string(1) "c" } array(13) { [0]=> string(3) "new" [1]=> string(3) "new" [2]=> string(3) "new" [3]=> string(3) "new" [4]=> string(3) "new" [5]=> string(1) "a" [6]=> string(1) "b" [7]=> string(3) "new" [8]=> string(3) "new" [9]=> string(3) "new" [10]=> string(3) "new" [11]=> string(3) "new" [12]=> string(1) "c" }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
28.15 ms | 407 KiB | 5 Q