Reply to Re: [PHP] Testing for an empty array (with null values)

Your name:

Reply:


Posted by Jochem Maas on 10/01/05 17:50

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

>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация