简体   繁体   English

取消设置父项为空

[英]Unset parent on empty

Please, someone ca help me with that? 拜托,有人可以帮我吗?

I want to unset the parent array key if any value inside of that array is null; 如果该数组内部的任何值为null,我想取消设置父数组键。

eg 例如

array
(
    0 => array
    (
        'type' => 'Main'
        'phone' => '11 555-1423'
        'foo' => array(
            0 => (
                'bar' => ''
            )
         )

    )
    1 => array
    (
        'type' => 'Personal'
        'phone' => ''
        'foo' => array()
    )
)

In this case I want to unset [0][foo] and [1]. 在这种情况下,我要取消设置[0] [foo]和[1]。

I think this is exactly what you want 我想这正是你想要的

function fclear(&$arr, $del){
    foreach($arr as $key=>&$val){
        if($val == '')
            return true;
        if(is_array($val)){
            $del = fclear($val, false);
                if($del == true)
                    unset($arr[$key]);
        }
    }
}

fclear($myarr,false);

you can look at the Code Sample , run it and see result. 您可以查看代码示例 ,运行它并查看结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM