Home  >  Article  >  Backend Development  >  How to detect whether a variable is set in php isset

How to detect whether a variable is set in php isset

藏色散人
藏色散人Original
2021-05-08 09:32:062071browse

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.

How to detect whether a variable is set in php isset

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 &#39;变量 $var 已经被设置&#39;;
} else {
    echo &#39;变量 $var 还未被设置&#39;;
}
?>

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn