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 :: how to log object laravel logger 
Php :: php json response to ajax 
Php :: wp_get_attachment_url 
Php :: Laravel Framework upgrade from older version 7.x to 8.x 
Php :: laravel array cast 
Php :: laravel blade @selected 
Php :: php camelcase to snake case 
Php :: write php online 
Php :: php random 
Php :: wordpress create shortcode 
Php :: php return new object 
Php :: curl php loop 
Php :: php multi condition if 
Php :: yii2 clear schema cache 
Php :: ci base url dynamic 
Php :: wordpress move debug.log 
Php :: laravel blade foreach index value 
Php :: get authinticated user id laravel 
Php :: load-styles.php 403 
Php :: laravel log reader 
Php :: wp reserved image size name 
Php :: custom error page htaccess 
Php :: PHP Fatal error: Uncaught Error: Call to undefined function mcrypt_encrypt() 
Php :: laravel collection max 
Php :: how to read sqlite file in php 
Php :: update wordpress query 
Php :: php clean user input 
Php :: laravel echo html 
Php :: carbon between hours 
Php :: Sum two numbers in PHP with HTML input form 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =