Home > Backend Development > PHP Tutorial > php 删除空数组

php 删除空数组

PHP中文网
Release: 2016-06-08 17:28:32
Original
1956 people have browsed it

php 删除空数组 

$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; 
 }
 */
Copy after login

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


方法二

function array_to_hashmap(& $arr, $keyField, $valueField = null) 
{ 
$ret = array(); 
if($valueField) { 
foreach ($arr as $row) { 
$ret[$row[$keyField]] = $row[$valueField]; 
} 
} else { 
foreach($arr as $row) { 
$ret[$row[$keyField]] = $row; 
} 
} 
return $ret; 
}
Copy after login

以上就是php 删除空数组 的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Related labels:
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template