Archive for May, 2007

How to remove an element from an array

Posted on: May 17th, 2007 | Category: PHP

Soo, I’m learning more and more php these days and today I stumbled onto a problem, which I couldn’t solve myself.

How do you remove an element from an array in php?

After a quick google search I found this:

foreach($array as $key => $value) {
          if($value == "" || $value == " " || is_null($value)) {
and if you want to create a new array with the keys reordered accordingly
$new_array = array_values($array);

Tnx to Scriptygoddess

This works okay, but I’m wondering if this is the best/quickest way to remove an element from an array?

And isn’t there a built-in function in php that does the same thing?