Strange PHP behavior: empty, !, and count -


someone can explain me if "freak" behavior should expect.

i'm debbuging code , got this:

i geting result on $data , create if sure it's $data have info.

so:

if(!$data || empty($data) || count($data) == 0) 

and aways geting in if.

so var_dump see , wow.

var_dump(!$data , empty($data) , count($data)); 

go this:

bool(true) bool(true) int(1) 

how count data = 1 , !$data = true , empty($data) = true?

i hope isn't stupid question, i'm sorry if is.

count returns number of elements in var. if var not array or object implemented countable interface, 1 returned. there 1 exception, if var null, 0 returned.

look @ php documentation http://php.net/manual/en/function.count.php


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -