3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $array = array( 'index1' => 'Deleted', 'index2' => 'numbers', 'index3' => 'test', 'index4' => 'Inserted', ); $specificIndex = 'index2'; $array1=array(); foreach($array as $key => $value){ if($key==$specificIndex){ $array1[$key] = $value; unset($array[$specificIndex]); } } print_r($array); print_r($array1);
based on nIdLY
Output for 4.3.0 - 7.2.0
Array ( [index1] => Deleted [index3] => test [index4] => Inserted ) Array ( [index2] => numbers )