<?php $array1 = ["banana","car","carrot"]; $needle = "car"; if (($index = array_search($needle, $array1)) !== false) { $array2[] = $array1[$index]; unset($array1[$index]); } var_export($array1); echo "\n---\n"; var_export($array2);
You have javascript disabled. You will not be able to edit any code.