search
HomeBackend DevelopmentPHP ProblemHow to check if a variable is defined in php

How to check if a variable is defined in php

Sep 21, 2019 pm 05:57 PM
phpvariabledefinitionexamine

How to check if a variable is defined in php

isset() function

Judge whether the variable has been set

Format: bool isset ( mixed var [, mixed var [, ...]] )

1. If the variable does not exist, it returns FALSE

2. If the variable exists and its value is NULL, also returns FALSE

3. If the variable exists and the value is not NULL, it returns TRUE

When checking multiple variables at the same time, TRUE will be returned only when each single item meets the previous requirement. , otherwise the result is FALSE.

empty() function

Check whether the variable is empty

Format:bool empty (mixed var)

1. If the variable does not exist, it returns TRUE

2. If the variable exists and its value is "", 0, "0", NULL,, FALSE, array() , var $var; and objects without any attributes, return TURE

3. If the variable exists and the value is not "", 0, "0", NULL,, FALSE, array(), var $ var; and objects without any attributes, return FALSE

is_null() function

Judge whether it is null

How to check if a variable is defined in php

Note:

1. Empty and isset will first check whether the variable exists, and then detect the variable value. is_null just checks the variable value directly to see if it is null, so if the variable is not defined, an error will occur!

2. The empty and isset input parameters must be a variable (php variables start with the $ character), and the is_null input parameter only needs to have a return value. (constants, variables, expressions, etc.).

In the PHP manual, their analysis is: empty, isset is a language structure rather than a function, so it cannot be called by variable functions.

Recommended tutorial: PHP video tutorial

The above is the detailed content of How to check if a variable is defined in php. 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool