Anemon · Mecha CMS

Array and objects.

$anemon::set()

Author: Taufik Nurrohman · 223 Views

Tweet

Set or replace array value recursively.

Anemon::set(array &$input, $key, $value = null, $NS = '.');

Example:

$array = [
    'foo' => 1,
    'bar' => [
        'baz' => 2,
        'qux' => 3
    ]
];

Anemon::set($array, 'bar.baz', '#');

Result:

$array = [
    'foo' => 1,
    'bar' => [
        'baz' => '#',
        'qux' => 3
    ]
];