From 78229b9a656ad48e00b716e70480d5c6745f7165 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Tue, 1 Aug 2006 07:26:41 +0000 Subject: [PATCH] Added Functions->array_strip_empty() --- dev/changes.txt | 1 + functions.php | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/dev/changes.txt b/dev/changes.txt index 4be5264..0cedda6 100644 --- a/dev/changes.txt +++ b/dev/changes.txt @@ -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 =============== diff --git a/functions.php b/functions.php index 380afaa..c1b5bee 100644 --- a/functions.php +++ b/functions.php @@ -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; + } } /*=====================================================================*\ -- 2.22.5