千万里不及你
2018-06-04 16:11:37浏览 4676
<?php
//去除多维数组中的空值
$arr1 = array("1","","2");
$arr2 = array("","3","4");
$arr3 = array("","5","");
$arr4 = array("11","","22");
$arr5 = array("","33","44");
$arr6 = array("","55","");
$arr7 = array("111","","222");
$arr8 = array("","333","444");
$arr9 = array("","555","");
$s_arr1 = array("0"=>$arr1,"1"=>$arr2,"2"=>$arr3);
$s_arr2 = array("0"=>$arr4,"1"=>$arr5,"2"=>$arr6);
$s_arr3 = array("0"=>$arr7,"1"=>$arr8,"2"=>$arr9);
$big_arr = array("0"=>$s_arr1,"1"=>$s_arr2,"2"=>$s_arr3);
$g_arr = get_arr($big_arr);
print_r($g_arr);
function get_arr($arr)
{
foreach ($arr as $k=>$v)
{
if(is_array($arr[$k]))
{
$arr[$k] = get_arr($arr[$k]);
}
else
{
if(empty($arr[$k]))
{
unset($arr[$k]);
}
}
}
return $arr;
}
?>