Report a bug 描述
bool empty ( mixed $var )
如果 var 是非空或非零的值,则 empty() 返回 FALSE。换句话说,""、0、"0"、NULL、FALSE、array()、var $var; 以及没有任何属性的对象都将被认为是空的,如果 var 为空,则返回 TRUE。
除了当变量没有置值时不产生警告之外,empty() 是 (boolean) var 的反义词。参见转换为布尔值获取更多信息。
Example #1 empty() 与 isset() 的一个简单比较。
复制代码 代码如下:
$var = 0;
// 结果为 true,因为 $var 为空
if (empty($var)) {
echo '$var is either 0 or not set at all';
}
// 结果为 false,因为 $var 已设置
if (!isset($var)) {
echo '$var is not set at all';
}
?>
Note: 因为是一个语言构造器而不是一个函数,不能被 可变函数 调用。
Note:
empty() 只检测变量,检测任何非变量的东西都将导致解析错误。换句话说,后边的语句将不会起作用: empty(addslashes($name))。
The following things are considered to be empty:
"" (an empty string)
0 (0 as an integer)
0.0 (0 as a float)
"0" (0 as a string)
NULL
FALSE
array() (an empty array)
var $var; (a variable declared, but without a value in a class)
对"空数组"的理解:array() (an empty array)
复制代码 代码如下:
$array1=array();
print_r($array1);
if(empty($array1)){
echo '对empty()来说是空数组(an empty array)';
}
else{
echo '对empty()来说是非空数组(an noempty array)';
}
?>
//显示结果:######################
Array
(
)
//对empty()来说是an empty array
###############################
$array1=array();
$array1[]='';
print_r($array1);
if(empty($array1)){
echo '对empty()来说是空数组(an empty array)';
}
else{
echo '对empty()来说是非空数组(an noempty array)';
}
?>
//显示结果:######################
Array
(
[0] =>
)
//对empty()来说是非空数组(an noempty array)
//###############################
//这个并不是空数组,因为它有一个元素为空字符(""),要注意和空字符("" (an empty string))区别;

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Laravel's service container and service providers are fundamental to its architecture. This article explores service containers, details service provider creation, registration, and demonstrates practical usage with examples. We'll begin with an ove

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 English version
Recommended: Win version, supports code prompts!

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools