How to detect whether a variable is set in php isset

藏色散人
Release: 2023-03-09 13:48:01
Original
2005 people have browsed it

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 [, ...]] )
Copy after login

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;;
}
?>
Copy after login

Run this example output:

变量 $var 已经被设置
Copy after login

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;
Copy after login

In the following situations, isset() returns TRUE:

$var = "";
$var = array();
$var = 0;
$var = false;
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!