scriptygoddess

21 Sep, 2004

PHP: Remove an element from an array

Posted by: Jennifer In: Lessons learned

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);

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

1 Response to "PHP: Remove an element from an array"

Featured Sponsors


  • Dave Grant Urban: I noticed the same thing; no display in FF if swfobject is in the body. Unfortunately, I can't get to the head section because I use GoDaddy's Quick S
  • C. Scott Asbach: Actually, I had accidentally looked at Chrome instead of Firefox when I thought that worked...(I develop with at least 3 browsers open all th time)
  • C. Scott Asbach: The solution that worked for me was: a:link img{text-decoration:none} Put that after your other a:link,a:visited,a:hover rules and it should wor

About


Advertisements