PHP如何判断数组是否为空

PHPz
Release: 2020-09-05 09:36:37
Original
2326 people have browsed it

PHP如何判断数组是否为空

PHP判断数组是否为空的方法:

empty功能:检测变量是否为”空”

说明:任何一个未初始化的变量、值为 0 或 false 或 空字符串”” 或 null的变量、空数组、没有任何属性的对象,都将判断为empty==true

注意1:未初始化的变量也能被empty检测为”空”

注意2:empty只能检测变量,而不能检测语句

<?php
$a = 0;
$b = &#39;&#39;;
$c = array();
if (empty($a)) echo &#39;$a 为空&#39; . "";
if (empty($b)) echo &#39;$b 为空&#39; . "";
if (empty($c)) echo &#39;$c 为空&#39; . "";
if (empty($d)) echo &#39;$d 为空&#39; . "";
Copy after login

更多相关知识,请访问PHP中文网

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!