Home  >  Article  >  Backend Development  >  PHP如何判断数组是否为空

PHP如何判断数组是否为空

PHPz
PHPzOriginal
2016-06-02 11:28:112325browse

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; . "";

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

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