Re: Testing for an empty array (with null values)

From: Date: Sat, 01 Oct 2005 14:50:37 +0000
Subject: Re: Testing for an empty array (with null values)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-223486@lists.php.net to get a copy of this message
zzapper wrote:
Hi, I can use if (count($somearray) > 0) to test for an empty array.
why don't you test it. $a = array(); $b = array(null, null, null); $c = array(false, false); $d = array(1, 1, 1); echo "array \$a: \n---------------------------\n"; var_dump(empty($a), count($a), array_filter($a), array_values($a)); echo "array \$b: \n---------------------------\n"; var_dump(empty($b), count($b), array_filter($b), array_values($b)); echo "array \$c: \n---------------------------\n"; var_dump(empty($c), count($c), array_filter($c), array_values($c)); echo "array \$d: \n---------------------------\n"; var_dump(empty($d), count($d), array_filter($d), array_values($d));
It is possible to have an array with null values which is effectively empty but fails the above as it's count (I belive is greater than 0).
look above.
Any ideas
plenty. hopefully the code above give you a few too :-)


« previous php.general (#223486) next »