How to use array_walk_recursive

前端 未结 3 1488
遥遥无期
遥遥无期 2021-01-13 15:20

How can I use array_walk_recursive() instead of this:

function check_value($val){
  if(is_array($val)){
    foreach($val as $key => $value)
          


        
3条回答
  •  忘掉有多难
    2021-01-13 15:50

    I think this should do the same thing. Note that argument of a function is passed as a reference (i.e. &$value).

    array_walk_recursive($array, function(&$value) {
        $value = clean_value($value);
    });
    

    For older PHP versions:

    function check_value(&$value) {
        $value = clean_value($value);
    }
    array_walk_recursive($array, 'check_value');
    

提交回复
热议问题