Re: isset

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

 



Richard Lynch wrote:
> On Mon, April 16, 2007 5:35 pm, Tim Earl wrote:
>> What about in the following context?
>>
>> $arr = array();
>> If (!empty($arr)) { }
>>
>> This is where i have found it to be the most usefull...
> 
> If I'm already certain that it's an array, I just use 'count' personally.
> 
> 'empty' takes a mixed data type, and could return TRUE for, say, 'foo'
> even though you are expecting an array there.
> 
> I think it's a better practice to use the "right" weapon and use
> count() on an array to see if it's empty or not.

php -r 'var_dump(count("foo"));'

outputs:
int(1)

so my strategy is usually

if (!empty($r) && is_array($r)) {
	// good to go.
}

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.

-- 
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