morpheus3g
asked on
delete an array entry
i have an array like this
$array=array("one","two"," bingo","th ree","four ");
i want to remove the "bingo" (i know his key)... i tried with " unset($array[2]); but then there's an "hole" in the array...
$array=array("one","two","
i want to remove the "bingo" (i know his key)... i tried with " unset($array[2]); but then there's an "hole" in the array...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
hi morpheus3g
This is the Best way my dear..........plzzzz use it and donot worry about the hole......
I assume you mean the missing key.. ie: 0, 1, 3, 4. If you add the array values function the numeric indexes will be reset, eg:
$array=array("one","two"," bingo","th ree","four ");
unset($array[2]);
$array = array_values($array);
rahulbhanot
This is the Best way my dear..........plzzzz use it and donot worry about the hole......
I assume you mean the missing key.. ie: 0, 1, 3, 4. If you add the array values function the numeric indexes will be reset, eg:
$array=array("one","two","
unset($array[2]);
$array = array_values($array);
rahulbhanot
foreach($array as $key => $value)
to itterate over the elements instead of a ugly
for ($i=0; $i<count($array); $i++)
It work alwyas, equal if there are holes in the array or not.
You can use sort($array) to get rid of the holes if you don't care about the order of your elements