PHP code example of crissi / array-key-change

1. Go to this page and download the library: Download crissi/array-key-change library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

crissi / array-key-change example snippets


$source = [
    'alpha' => [
        'bravo' => [
            'nested' => [1, 2, 3]
        ]
    ],
    'whiskey' => [44,45, 45],
    'charlie' => [
        ['foo' => '222'],
        ['foo' => '44444'],
        ['foo' => '444'],
        [
            'foo' => 'text',
            'lol' => '3434'
        ],
    ],
];

$result = ArrayKeyChange::in($source)
    ->skipMissingPaths()
    ->modify([
        'alpha.bravo.nested' => 'delta',
        'alpha' => 'foxtrot',
        'alpha.bravo' => 'echo',
        'charlie.*.lol' => 'rofl',
        'charlie' => 'omega'
    ]);