PHP Array isset and empty
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'] ) {};
true
if the value is set to ''
.false
if the value is set to null
.$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
.
true
if set to ''
, or null
$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.