How to use empty function in php

王林
Release: 2023-03-09 17:02:02
Original
3502 people have browsed it

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

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

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!

Related labels:
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