Home > php教程 > php手册 > php 数组之删除空数组程序

php 数组之删除空数组程序

WBOY
Release: 2016-06-13 09:55:50
Original
876 people have browsed it

删除空元素的数组方法很多了,我今天来介绍两种经典的方法,一个是利用了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
)


实例

 

 代码如下 复制代码

$fangId = PostGet('houseId'); // 取得地址栏值
 $tempArray = array_filter(explode('_',$fangId),"filter"); //以__分成数组并且删除空数组
 
 if( is_array($tempArray) && !empty( $tempArray ) ) //判断数组是否有值
 {
  print_r($tempArray); //测试输出
 }
 else
 {
  MessAge('请选择对比较楼盘','list.php');
 }
 

 function filter($var)  处理函数
 {
   if($var == '')
   {
    return false;
   }
   return true;
 }


测试方法:/compare.php?houseId=2306__2307__2303__2308


更多详细内容请查看:http://www.bKjia.c0m/phper/21/b427d2b7535fc76ad744d41f825590dc.htm

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