Skip to main content

Posts

Showing posts with the label php empty

Difference between empty, null & isset

1. Null A variable is considered to be null if: it has been assigned the constant NULL. it has been unset(). it has not been set to any value yet. Note : empty array is converted to null by non-strict equal '==' comparison. Use is_null() or '===' if there is possible of getting empty array. eg: 1 $a = array(); $a == null  <== return true $a === null < == return false is_null($a) <== return false eg: 2 Note the following: $test =''; if (isset($test)){     echo 'Variable test exists'; } if (empty($test)){ // same result as $test = ''     echo ' and is_empty'; } if ($test == null){ // not the same result as is_null($test)     echo 'and is_null'; } The result would be: Variable test exists and is_empty and is_null eg : 3 But for the following code...: $test =''; if (isset($test)){     echo 'Variable test exists'; } if (empty($test)){ // same result as $test =...