Testing if an array is empty

This is a discussion on Testing if an array is empty within the PHP Language forums, part of the PHP Programming Forums category; On 13.08.2007 17:32 zzapper wrote: > Hi, > Have tried to google this without 100% satisfaction. > &...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #11 (permalink)  
Old 08-13-2007
gosha bine
 
Posts: n/a
Default Re: Testing if an array is empty

On 13.08.2007 17:32 zzapper 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



if(array_filter($ary))
$ary contains at least one non-empty element
else
$ary contains 0 elements or all elements are empty


--
gosha bine

makrell ~ http://www.tagarga.com/blok/makrell
php done right ;) http://code.google.com/p/pihipi
Reply With Quote
  #12 (permalink)  
Old 08-13-2007
Rik
 
Posts: n/a
Default Re: Testing if an array is empty

On Mon, 13 Aug 2007 18:36:20 +0200, gosha bine <stereofrog@gmail.com>
wrote:
> On 13.08.2007 17:32 zzapper 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

>
>
> if(array_filter($ary))
> $ary contains at least one non-empty element
> else
> $ary contains 0 elements or all elements are empty



Hmmz, didn't know this would work, but offcourse simple converting to
boolean would do the trick, away with my functions :)
--
Rik Wasmus
Reply With Quote
  #13 (permalink)  
Old 08-13-2007
zzapper
 
Posts: n/a
Default Re: Testing if an array is empty

On Aug 13, 5:39 pm, Rik <luiheidsgoe...@hotmail.com> wrote:
> On Mon, 13 Aug 2007 18:36:20 +0200, gosha bine <stereof...@gmail.com>
> wrote:
>
> > On 13.08.2007 17:32zzapperwrote:
> >> 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

>
> > if(array_filter($ary))
> > $ary contains at least one non-empty element
> > else
> > $ary contains 0 elements or all elements are empty

>

Like it

Are we going to vote this best solution?

zzapper


Reply With Quote
  #14 (permalink)  
Old 08-13-2007
Rik
 
Posts: n/a
Default Re: Testing if an array is empty

On Mon, 13 Aug 2007 22:33:27 +0200, zzapper <zzapper@gmail.com> wrote:

> On Aug 13, 5:39 pm, Rik <luiheidsgoe...@hotmail.com> wrote:
>> On Mon, 13 Aug 2007 18:36:20 +0200, gosha bine <stereof...@gmail.com>
>> wrote:
>>
>> > On 13.08.2007 17:32zzapperwrote:
>> >> 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

>>
>> > if(array_filter($ary))
>> > $ary contains at least one non-empty element
>> > else
>> > $ary contains 0 elements or all elements are empty

>>

> Like it
>
> Are we going to vote this best solution?
>


Except it might be better for the function to return false instead of an
empty array, yes indeed, I'd say so :)

--
Rik Wasmus
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 08:16 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0