3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $array = array( '1st' => 'a', '2nd' => 'b', '3rd' => 'b' ); foreach($array as $key => &$value) { if($value === 'a') { $array['1st'] = '1'; $array['2nd'] = '2'; array_splice($array, 0, 0, array('x')); //array pointer 초기화 //array_splice($array, count($array), 0, array('y')); //array pointer 초기화 } var_dump($key . ' - ' . $value); } unset($value);
based on 5kYoK
Output for 7.0.0 - 7.3.0beta1
string(7) "1st - 1" string(7) "3rd - b"
Output for 5.6.0 - 5.6.28
string(7) "1st - 1" string(7) "2nd - 2" string(7) "3rd - b"
Output for 5.5.0 - 5.5.35
string(7) "1st - 1" string(5) "0 - x" string(7) "1st - 1" string(7) "2nd - 2" string(7) "3rd - b"