lithium\util\Set::insert()
Inserts $data
into an array as defined by $path
.
Parameters
-
mixed
$list
Where to insert into.
-
mixed
$path
A dot-delimited string.
-
array
$data
Data to insert.
Returns
arraySource
public static function insert($list, $path, $data = []) {
if (!is_array($path)) {
$path = explode('.', $path);
}
$_list =& $list;
foreach ($path as $i => $key) {
if (is_numeric($key) && (integer) $key > 0 || $key === '0') {
$key = (integer) $key;
}
if ($i === count($path) - 1) {
$_list[$key] = $data;
} else {
if (!isset($_list[$key])) {
$_list[$key] = [];
}
$_list =& $_list[$key];
}
}
return $list;
}