• php 过滤掉多维数组空值


    
    
    //过滤掉空值
    function filter_array($arr, $values = ['',[]]){
        foreach ($arr as $k => $v) {
            if (is_array($v) && count($v)>0) {
                $arr[$k] = filter_array($v, $values);
            }
            foreach ($values as $value) {
                if ($v === $value) {
                    unset($arr[$k]);
                    break;
                }
            }
        }
        return $arr;
    }
    
    
    
    //过滤掉空值
    function filter_array($arr){
        $narr = array();
        while(list($key, $val) = each($arr)){
            if (is_array($val)){
                $val = filter_array($val);
                if (count($val)!=0){
                    $narr[$key] = $val;
                }
            }else{
                if (trim($val) != ""){
                    $narr[$key] = $val;
                }
            }
        }
        unset($arr);
        return $narr;
    }
  • 相关阅读:
    idea
    C#
    mysql
    .net5
    .net5
    .net5
    .net5
    .net5
    .net5
    .net5
  • 原文地址:https://www.cnblogs.com/chengfengchi/p/10796108.html
Copyright © 2020-2023  润新知