PHP: Reorder arrays after unset()

SOAMIESOBBEFS

New Member
There are 2 functions involved.[*]Search array items for a given string[*]unset() array item if string not found \[code\] $array = array("first", "second", "third", "fourth");\[code\]foreach($array as $i=> $string) { if(stristr($string, "e")) { unset($array[$i]); } }\[/code\]\[/code\]"second" is the array item with the character 'e'. If its unset, $array[1] would be left empty\[code\]$array[0] = "first" $array[1] = "" $array[2] = "third" $array[3] = "fourth"\[/code\]I want $array[1] to be removed from the array (like in array_shift() ), so that "third" takes the place of "second" and "fourth" the place of "third"\[code\]$array[0] = "first" $array[1] = "third" $array[2] = "fourth"\[/code\]thanks
 
Back
Top