Home > Article > Backend Development > How to determine whether a variable has a set function in php
php method to determine whether a variable has a set function: You can use the isset() function to determine. The isset() function is used to detect whether a variable has been set and is not NULL. Returns TRUE if the specified variable exists and is not NULL, otherwise returns FALSE.
isset() function is used to detect whether the variable has been set and is not NULL.
(Recommended tutorial: php graphic tutorial)
If you have used unset() to release a variable, and then pass isset() to judge, it will return FALSE. If you use isset() to test a variable that is set to NULL, it will return FALSE. Also note that the null character ("\0") is not equivalent to PHP's NULL constant.
Syntax:
bool isset ( mixed $var [, mixed $... ] )
Return value:
If the specified variable exists and is not NULL, TRUE is returned, otherwise FALSE is returned.
(Learning video recommendation: php video tutorial)
Example:
<?php $var = ''; // 结果为 TRUE,所以后边的文本将被打印出来。 if (isset($var)) { echo "变量已设置。" . PHP_EOL; } // 在后边的例子中,我们将使用 var_dump 输出 isset() 的返回值。 // the return value of isset(). $a = "test"; $b = "anothertest"; var_dump(isset($a)); // TRUE var_dump(isset($a, $b)); // TRUE unset ($a); var_dump(isset($a)); // FALSE var_dump(isset($a, $b)); // FALSE $foo = NULL; var_dump(isset($foo)); // FALSE ?>
Run result:
变量已设置。 bool(true) bool(true) bool(false) bool(false) bool(false)
The above is the detailed content of How to determine whether a variable has a set function in php. For more information, please follow other related articles on the PHP Chinese website!