https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/
http://www.zomeoff.com/php-fast-way-to-determine-a-key-elements-existance-in-an-array/
$people = array(
'one' => 'Eric', // true
'two' => '', // false
'three' => null, // false
'four' => 0, // false
'five' => '0', // false
'six' => ' ', // true
);
if ( $people['one'] ) {};
- This will check to see if there is a value for an item in an array.
- This will return
true
if the value is set to''
. - This will return
false
if the value is set tonull
.
$people = array(
'one' => 'Eric', // true
'two' => '', // true
'three' => null, // false
'four' => 0, // true
'five' => '0', // true
'six' => ' ', // true
);
if ( isset( $people['one'] ) ) {};
Only returns false if the value is set to null
.
- Will return
true
if set to''
, ornull
- These are values empty will evaluate as 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)
$people = array(
'one' => 'Eric', // false
'two' => '', // true
'three' => null, // true
'four' => 0, // true
'five' => '0', // true
'six' => ' ', // false
);
if ( empty( $people['one'] ) ) {};
So the big difference here is that empty
will also return true if the value is ''
. This
makes it the more safe function to use if you want to make sure ''
isn't accepted.