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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 :-)



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux