You are here: Re: Testing if an array is empty « PHP Programming Language « IT news, forums, messages
Re: Testing if an array is empty

Posted by Rik on 08/13/07 15:42

On Mon, 13 Aug 2007 17:32:33 +0200, zzapper <zzapper@gmail.com> wrote:
> Have tried to google this without 100% satisfaction.
>
> A function reads a mysql record into an array and returns it, if it
> doesnt exist it returns '' or FALSE.
>
> What ways do I have to test that my returned array is not empty

Something like the following?
<?php
if(empty($array)) echo '$array is empty';
?>

If you want an empty string, false, and an empty array handled seperatel=
y, =

you can use the following:

<?php
if($return=3D=3D=3Dfalse){ //notice the triple '=3D'
echo 'Function returned false';
} else if($return =3D=3D=3D ''){
echo 'Function returned empty string.';
} else if(is_array($return) && empty($return)){
echo 'Function returned empty array.';
} else {
echo 'Function returned:';
var_dump($return);
}
?>

-- =

Rik Wasmus

 

Navigation:

[Reply to this 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

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