delete an array entry

i have an array like this

$array=array("one","two","bingo","three","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...
LVL 2
morpheus3gAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Diablo84Commented:
hi morpheus3g

>> but then there's an "hole" in the array

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","three","four");
unset($array[2]);
$array = array_values($array);

Diablo84

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hernst42Commented:
Yes if you unset an array element there is a hole in the index, but what's the problem with that. If you use
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
rahulbhanotCommented:
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","three","four");
unset($array[2]);
$array = array_values($array);

rahulbhanot
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.