Re: Re: unset empty elements in an array
| From: | Paul Bissex | Date: | Mon, 12 Jul 2004 17:14:35 +0000 |
| Subject: | Re: Re: unset empty elements in an array | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-190261@lists.php.net to get a copy of this message | ||
On Tue, 13 Jul 2004 01:57:48 +1000, Justin French
<justin.french@indent.com.au> wrote:
> [...] My hope
> was that there was such a function to delete empty array elements
> already defined in PHP, but since it appears there isn't, I'll just
> keep including my own from a library file.
How about array_filter()? From the docs: "If the callback function is
not supplied, array_filter() will remove all the entries of input
that are equal to FALSE."
$a = array ('a' => 'foo', 'b' => '', 'c'
=> null, 'd' => 99, 'e' => 0);
print_r (array_filter ($a));
// Output:
Array
(
[a] => foo
[d] => 99
)
As a previous poster noted, though, this will only work for you if "0"
and the empty string et al. are not significant in your application.
pb
--
paul bissex, e-scribe.com -- database-driven web development
413.585.8095
69.55.225.29
01061-0847
72°39'71"W 42°19'42"N