Added Functions->array_strip_empty()
authorRobert Sesek <rsesek@bluestatic.org>
Tue, 1 Aug 2006 07:26:41 +0000 (07:26 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Tue, 1 Aug 2006 07:26:41 +0000 (07:26 +0000)
dev/changes.txt
functions.php

index 4be5264a0e83810dce53c96fd80176a259642bc1..0cedda6d5112dbf26aa555f631c37530f648b0ec 100644 (file)
@@ -8,6 +8,7 @@
 - Added a parameter in API->delete() to optionally stop the running of API->set_existing() [api.php]
 - Changed some of the API error messages to reflect what actually caused the error [api.php]
 - Made the Printer->row_text() colspan parameter work more normally [printer.php]
+- Added Functions->array_strip_empty() to strip empty and null elements from a given array [functions.php]
 
 2.0.0
 ===============
index 380afaa614282513803c9653db36234519626ca9..c1b5bee213deebc1fc54b45bcb0d60ddf3c8638e 100644 (file)
@@ -632,6 +632,33 @@ class Functions
                $text = str_replace("\n", $convert_to, $text);
                return $text;
        }
+       
+       // ###################################################################
+       /**
+       * Removes all empty() [by PHP's standards] elements in an array. This
+       * can be used in place of using PREG_SPLIT_NO_EMPTY.
+       *
+       * @access       public
+       *
+       * @param        array   An array to strip empties from
+       *
+       * @return       array   Full-valued array
+       */
+       function array_strip_empty($array)
+       {
+               foreach ($array AS $key => $value)
+               {
+                       if (is_array($array["$key"]))
+                       {
+                               $array["$key"] = $this->array_strip_empty($array["$key"]);
+                       }
+                       else if (empty($value) OR is_null($value))
+                       {
+                               unset($array["$key"]);
+                       }
+               }
+               return $array;
+       }
 }
 
 /*=====================================================================*\