Home >Backend Development >PHP Problem >How to use empty function in php

How to use empty function in php

王林
王林Original
2021-05-13 15:26:573533browse

The method of using empty function in php is [bool empty (mixed $var)]. The empty() function is used to check whether a variable is empty. If the variable does not exist or the value is equal to false, it will be considered not to exist.

How to use empty function in php

The operating environment of this article: windows10 system, php 7.3, thinkpad t480 computer.

The empty() function in php is used to check whether a variable is empty. empty() determines whether a variable is considered empty. When a variable does not exist, or its value is equal to FALSE, then it is considered not to exist. empty() does not generate a warning if the variable does not exist.

empty() After version 5.5, it supports expressions, not just variables.

Syntax structure:

bool empty ( mixed $var )

Example:

<?php
$ivar1=0;
$istr1=&#39;phpcncncn&#39;;
if (empty($ivar1)){
    echo &#39;$ivar1&#39; . " 为空或为 0。" . PHP_EOL;
}else{
    echo &#39;$ivar1&#39; . " 不为空或不为 0。" . PHP_EOL;
}if (empty($istr1)){
    echo &#39;$istr1&#39; . " 为空或为 0。" . PHP_EOL;
}else{
    echo &#39;$istr1&#39; . " 字符串不为空或不为0。" . PHP_EOL;
}
?>

Running result:

$ivar1 is empty or 0.

$istr1 The string is not empty or 0.

Free learning video sharing: Introduction to programming

The above is the detailed content of How to use empty function 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