算法:手写一个删除多维数组中指定value的函数

function deletedigui($arr,$value){
    if(empty($arr) || !is_array($arr) || empty($value)) return [];

    foreach($arr as $key => &$val){
        if($val == $value){
            unset($arr[$key]);
        }
        if(is_array($val)){
            $val=deletedigui($val,$value);
        }
    }

    return $arr;
}


$arr = ['key1'=>['zjx'],'key2'=>'zjx','key3'=>['key4'=>['key5'=>'zjx','key6'=>'xml']],'key7'=>['zjx','xml'],'key8'=>['key9'=>['key10'=>'zjx','key11'=>['key12'=>'zjx']]]];

var_dump(deletedigui($arr,'zjx'));

你可能感兴趣的:(算法:手写一个删除多维数组中指定value的函数)