php 如何判断数组是否为空
1、在windows系统上安装xamp,作为web网站的服务器,用于运行php网页代码,在xampp安装完成后启动xampp control,将apache服务启动
2、使用php创建数组,并在页面上输出数组内容使用array函数构建数组:<?php$citys = array("Beijing","Shanghai","Shenzhen");echo "The level one cities:".$citys[0].",".$citys[1].",".$citys[2];?>
3、使用php count函数进行判断数组是否为空的方法1:使用count统计函数获取数组大小,如果是返回结果为0则表示数组为空<?php$citys = array("Beiji荏鱿胫协ng","Shanghai","Shenzhen");echo "The level one cities:".$citys[0].",".$citys[1].",".$citys[2];$badcities = array();echo "<br>";echo "There are ".count($citys)." first class cities.";echo "There are ".count($badcities)." bad cities.<br>";if (count($badcities)>0){ echo "The badcities array is not empty";}else{ echo "The badcities array is empty";}echo "<br>"; ?>
4、使用php empty函数进行判断数组是否为空的方法2:使用empty函数,根据返回值true或酆璁冻嘌false来判碘钹阏螗断if(empty($badcities)){ echo "The badcities array is empty by using the empty function";} else{ echo "The badcities array is not empty by using the empty function";}
5、使用php is_null函数判断数组是否null值(为初始化)