How to rename array keys in PHP?

前端 未结 10 1180
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 03:39

When I var_dump on a variable called $tags (a multidimensional array) I get this:

Array
(
    [0] => Array
        (
            [name] => tabbing
            [url         


        
10条回答
  •  [愿得一人]
    2020-11-28 04:34

    Recursive php rename keys function:

    function replaceKeys($oldKey, $newKey, array $input){
        $return = array(); 
        foreach ($input as $key => $value) {
            if ($key===$oldKey)
                $key = $newKey;
    
            if (is_array($value))
                $value = replaceKeys( $oldKey, $newKey, $value);
    
            $return[$key] = $value;
        }
        return $return; 
    }
    

提交回复
热议问题