Re: isset

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, April 16, 2007 8:06 pm, Robert Cummings wrote:
> On Mon, 2007-04-16 at 19:05 -0500, Richard Lynch wrote:
>> On Mon, April 16, 2007 6:10 pm, Jochem Maas wrote:
>> > if I know it's an array I'll definitely use empty() over count()
>> ....
>> > count() needs to actually count the items where as empty() can
>> return
>> > false
>> > as soon as it finds a singel element ... maybe I'm mistaken - if
>> so
>> > please
>> > put me right.
>>
>> You're wrong.
>>
>> The count is maintained internally as items are added/removed, and
>> it
>> is an O(1) operation for PHP to "count" the array, as it already
>> knows
>> the answer and just returns it.
>
> Fastest way to check if an array has elements...
>
> <?php
>
> if( $array )
> {
> }
>
> ?>

IIRC, in olden days of PHP 3.x, if the first element was '0' or 0,
then this test would result in FALSE...

Which is not to say it's "bad" now, but to explain why an old hand
might be leery of using it.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux