Return to Snippet

Revision: 17487
at September 7, 2009 05:32 by jeffery2k2610


Initial Code
<?
function array_non_empty_items($input) {
    // If it is an element, then just return it
    if (!is_array($input)) {
      return $input;
    }

    $non_empty_items = array();

    foreach ($input as $key => $value) {
      // Ignore empty cells
      if($value) {
        // Use recursion to evaluate cells
        $non_empty_items[$key] = array_non_empty_items($value);
      }
    }

    // Finally return the array without empty items
    return $non_empty_items;
  }
  
  ?>

Initial URL

                                

Initial Description

                                

Initial Title
Remove empty items from a multidimensional array in PHP

Initial Tags

                                

Initial Language
PHP