scriptygoddess RSS Feed
 
 
 
 

PHP: Remove an element from an array

Found on this thread

I needed to remove elements from an array that were either blank, nothing but a space, or null.
foreach($array as $key => $value) {
if($value == "" || $value == " " || is_null($value)) {
unset($array[$key]);
}
}
/*
and if you want to create a new array with the keys reordered accordingly…
*/
$new_array = array_values($array);

One Response to “PHP: Remove an element from an array”

  1. 1
    The Original Frish.nl - by Rogier Strobbe » Blog Archive » How to remove an element from an array:

    [...] Tnx to Scriptygoddess [...]

Bookmarks

WordPress Resources

Meta

Random Stuff