|
Posted by Rik on 08/13/07 16:10
On Mon, 13 Aug 2007 17:57:18 +0200, zzapper <zzapper@gmail.com> wrote:
> On Aug 13, 4:42 pm, "R. Rajesh Jeba Anbiah"
> <ng4rrjanb...@rediffmail.com> wrote:
>> On Aug 13, 8:32 pm, zzapper <zzap...@gmail.com> wrote:
>>
>> > Hi,
>> > 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
>>
>> http://in2.php.net/empty
>
> Hi
> The problem I have with empty() is as follows
>
>
> <?php
> $fred=3Darray ('');
> if (empty($fred)) { echo "empty";}
> else {echo 'not empty';}
> ?>
>
> reports not empty?
Indeed. An array with zero values is empty, an array with values (be it =
=
NULL, false, whatever) is not.
If you want to know wether an array consists only of 'empty' values (doe=
s =
_not_ work recursively):
<?php
//sorry, can't think of a good name:
function only_empty_array_values($array){
$filtered =3D array_filter($array,'_not_empty');
return empty($filtered);
}
function _not_empty($var){
return !empty($var);
}
$ar =3D array('',false,null);
$check =3D only_empty_array_values($ar);
?>
Allthough it could be better, depending on circumstances, to rewrite the=
=
function that returns this 'array of empties' to one that simply returns=
=
false instead of the array if there are no results.
-- =
Rik Wasmus
Navigation:
[Reply to this message]
|