Re: Testing if an array is empty
- From: Rik <luiheidsgoeroe@xxxxxxxxxxx>
- Date: Mon, 13 Aug 2007 17:42:42 +0200
On Mon, 13 Aug 2007 17:32:33 +0200, zzapper <zzapper@xxxxxxxxx> 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 seperately, you can use the following:
<?php
if($return===false){ //notice the triple '='
echo 'Function returned false';
} else if($return === ''){
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
.
- References:
- Testing if an array is empty
- From: zzapper
- Testing if an array is empty
- Prev by Date: Re: Testing if an array is empty
- Next by Date: Re: Testing if an array is empty
- Previous by thread: Re: Testing if an array is empty
- Next by thread: Re: Testing if an array is empty
- Index(es):
Relevant Pages
|