Function isset()
Determines whether a variable is set and is not NULL.
If the variable was disabled using unset()
, it will no longer be set. isset()
will return FALSE if it tests a variable that has been set to NULL. Also note that the NULL byte ("\0")
not equivalent to the PHP constant NULL.
If multiple parameters are specified, then isset()
will return TRUE only if all parameters are set. The evaluation goes from left to right and stops as soon as an undefined variable is encountered.
If you are not using isset()
, the script will generate a warning, with isset()
you can prevent this.
a For example, the reason for using isset()
is to detect if the key is inside an array.
eg:
<?php $a = array ('test' => 1, 'hello' => NULL, 'pie' => array('a' => 'apple')); var_dump(isset($a['test']));
The problem with your example is the operator !
in PHP NOT
, therefore, if you get the same result in the if if line, but the first line will display an Undefined variable, because there is no $name
variable, the second if you do NOT
before $name
variable
<?php if(!$name){//this will display a warning: Undefined variable. echo 'Name is not set'; } $name=0; if(!$name){//check the not value of $name. echo 'Name is true'; } ?>
source share