PHP recursion print all elements of a multidimensional array with keys

前端 未结 5 706
暗喜
暗喜 2020-12-11 20:26

I found the following code, which prints all the elements of an array fine. How can I modify it to print a key one time and then all the values corresponding to the key, the

5条回答
  •  死守一世寂寞
    2020-12-11 21:26

    function printAll($a) {
        if (!is_array($a)) {
            echo $a, ' ';
            return;
        }
    
        foreach($a as $k => $value) {
             if($k<10){
                 printAll($k);
                 printAll($value);
            }
        }
    }
    

提交回复
热议问题