Is There A Difference Between strlen()==0 and empty()?
There are a couple cases where they will have different behaviour:
empty('0'); // returns true,
strlen('0'); // returns 1.
empty(array()); // returns true,
strlen(array()); // returns null with a Warning in PHP>=5.3 OR 5 with a Notice in PHP<5.3.
empty(0); // returns true,
strlen(0); // returns 1.
strlen
is to get the number of characters in a string while empty
is used to test if a variable is empty
Meaning of empty:
empty("") //is empty for string
empty(0) // is empty for numeric types
empty(null) //is empty
empty(false) //is empty for boolean
The following things are considered to be empty:
"" (an empty string)
0 (0 as an integer)
0.0 (0 as a float)
"0" (0 as a string)
NULL
FALSE
array() (an empty array)
var $var; (a variable declared, but without a value in a class)
strlen() simply check if the the string len is 0. It does not check for int, float etc. What is your situation.
reference