$arr= array("");
$result = empty($arr);
//$result = false
$arr = array();
$result = empty($arr);
代码如下 |
复制代码 |
$arr= array(array(),array(),array());
$str = implode(',',$arr);
if(empty($str)) echo "空";
else echo "非空";
|
//$result = true
代码如下 |
复制代码 |
$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
)
|
implode();
Use implode() to output the array as a string and determine whether the output string is empty. At first glance, it seems to be a good method, but unfortunately, like the previous point, it does not work for arrays with more than two dimensions. For example:
The code is as follows
|
Copy code
|
$arr= array(array(),array(),array());
$str = implode(',',$arr);
| if(empty($str)) echo "empty";
else echo "not empty";
array_filter function
The code is as follows
|
Copy code
$str1_array=array('Yiju Tutorial Network','','http://www.bKjia.c0m','','1654','');
$str1_array=array_filter($str1_array);
print_r($str1_array);
?>Results
Array
(
[0] => Yiju Tutorial Network
[2] => http://www.bKjia.c0m
[4] => 1654
)
count,size() function
These two functions are method codes for judging empty arrays
$arr= array("");
echo count($arr);
echo size($arr);
//Output 1
http://www.bkjia.com/PHPjc/628799.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/628799.htmlTechArticleMany friends ask how to judge hollow arrays in PHP. Let me summarize some commonly used program codes for judging empty arrays. Friends who need to know can enter for reference. empty function, this is the judgment...
|
|
|