Search
 
SCRIPT & CODE EXAMPLE
 

PHP

change key with the value php

$arr[$newkey] = $arr[$oldkey];
unset($arr[$oldkey]);
Comment

replace key in php

### Deeply recursive change keys with array and object data
public function recursiveChangeKey($arr, $set)
    {
        //$arr => original array
        //$set => array containing old keys as keys and new keys as values

        if (!is_array($arr) && !is_object($arr) || !is_array($set)) {
            return $arr;
        }
        $newArr = [];
        if (is_array($arr) && is_array($set)) {
            foreach ($arr as $k => $v) {
                $key = array_key_exists($k, $set) ? $set[$k] : $k;
                $newArr[$key] = is_array($v) ? self::recursiveChangeKey($v, $set) : $v;
            }
        } elseif (is_object($arr) || is_object($set)) {
            $set = (array) $set;
            foreach ($arr->toArray() as $k => $v) {
                $key = array_key_exists($k, $set) ? $set[$k] : $k;
                $newArr[$key] = is_array($v) ? self::recursiveChangeKey($v, $set) : $v;
            }
        }
        return $newArr;
    }
Comment

PREVIOUS NEXT
Code Example
Php :: get value by today yesterday in laravel 
Php :: get substring after character php 
Php :: laravel sum relationship column 
Php :: how to limit word in php 
Php :: hide error in php 
Php :: how validate the becrypt password in laravel 
Php :: php required 
Php :: php get IP country 
Php :: snap store phpstrom 
Php :: delete all records from table using button laravel Eloquent 
Php :: how to echo only certain character number in php 
Php :: how to call a helper function in blade 
Php :: for in php 
Php :: upload file in php 
Php :: get public_html directory php 
Php :: PHP mysqli_close function 
Php :: random string generator php 
Php :: Syntax error or access violation: 1071 Specified key was too long; 
Php :: get current time in php 
Php :: php add property to object 
Php :: send attachment in mail php 
Php :: magento getcollection get first 
Php :: how to use a session in blade 
Php :: laravel carbon isoformat 
Php :: generate laravel event 
Php :: timezone php 
Php :: validation in laravel 
Php :: web api return json example in php 
Php :: how to create an associative array in php 
Php :: brew install php 5.6 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =