Home > php教程 > php手册 > php 判断空数组程序代码

php 判断空数组程序代码

WBOY
Release: 2016-06-13 10:16:22
Original
868 people have browsed it

很多朋友问php中空数组怎么判断,下面我来给大家总结一些常用的判断空数组程序代码,有需要了解的朋友可进入参考。

empty函数,这个是判断数组值为空

 代码如下 复制代码

$arr= array("");
$result = empty($arr);
//$result = false
$arr = array();
$result = empty($arr);
//$result = true


implode();

用implode()将数组输出为字符串,判断输出的字串是否为空。初看上去似乎是个不错的方法,可惜跟上一点一样,对于二维以上数组就不行了。举个例子:

 代码如下 复制代码

$arr= array(array(),array(),array());

$str = implode(',',$arr);

if(empty($str)) echo "空";

else echo "非空";


array_filter函数

 代码如下 复制代码


$str1_array=array('一聚教程网','','http://www.bKjia.c0m','','1654','');
$str1_array=array_filter($str1_array);
print_r($str1_array);
?>

结果

Array
(
[0] => 一聚教程网
[2] => http://www.bKjia.c0m
[4] => 1654
)

count,size()函数

这两个函数是判断空数组的方法代码


$arr= array("");
echo count($arr);
echo size($arr);
//输出1

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template