array_values recursive php

前端 未结 5 792
粉色の甜心
粉色の甜心 2020-12-10 16:12

Let\'s say I have an array like this:

Array
(
    [id] => 45
    [name] => john
    [children] => Array
    (
        [45] => Array
            (         


        
5条回答
  •  猫巷女王i
    2020-12-10 16:44

    This should do it:

    function array_values_recursive($arr, $key)
    {
        $arr2 = ($key == 'children') ? array_values($arr) : $arr;
        foreach ($arr2 as $key => &$value)
        {
            if(is_array($value))
            {
                $value = array_values_recursive($value, $key);
            }
        }
        return $arr2;
    }
    

提交回复
热议问题