php isset function is to detect whether the variable is set. Its syntax is "bool isset( mixed var [, mixed var [, ...]] )". If the detected variable exists, TRUE will be returned. Otherwise return FALSE.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
isset() is used to detect whether the variable is set.
isset()
PHP isset() is used to detect whether one or more variables are set. If the detected variable exists, it returns TRUE, otherwise it returns FALSE.
Syntax:
bool isset( mixed var [, mixed var [, ...]] )
If multiple variables are detected, as long as one of the variables exists, the detection result will return TRUE.
Example:
<?php $var = 1; if(isset($var)){ echo '变量 $var 已经被设置'; } else { echo '变量 $var 还未被设置'; } ?>
Run this example output:
变量 $var 已经被设置
Note
isset() can only be used to detect variables, passing any other parameters will Cause parsing errors.
isset() is a language structure rather than a function, so it cannot be called by variable functions.
Tips
In the following situations, isset() returns FALSE:
// 变量被设置为 null $var = null; // 被 unset() 释放了的变量 unset($var); // 类里变量被 var 关键字声明,但尚未设定 var $var;
In the following situations, isset() returns TRUE:
$var = ""; $var = array(); $var = 0; $var = false;
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to detect whether a variable is set in php isset. For more information, please follow other related articles on the PHP Chinese website!