Heim  >  Artikel  >  Backend-Entwicklung  >  PHP如何判断数组是否为空

PHP如何判断数组是否为空

PHPz
PHPzOriginal
2016-06-02 11:28:112326Durchsuche

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中文网

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn