<?php
function assignArrayByPath(&$arr, $path, $value, $separator = '_') {
$keys = explode($separator, $path);
foreach ($keys as $key) {
$arr = &$arr[$key];
}
$arr = $value;
}
$array = [
'max_size_video' => 50000,
'max_size_photo' => 8000,
'token_expire' => 100,
'dns' => 'mydns.fr',
];
foreach ($array as $key => $value) {
unset($array[$key]);
assignArrayByPath($array, $key, $value);
}
var_export($array);
- Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
- array (
'max' =>
array (
'size' =>
array (
'video' => 50000,
'photo' => 8000,
),
),
'token' =>
array (
'expire' => 100,
),
'dns' => 'mydns.fr',
)
- Output for 8.3.5
- Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
array (
'max' =>
array (
'size' =>
array (
'video' => 50000,
'photo' => 8000,
),
),
'token' =>
array (
'expire' => 100,
),
'dns' => 'mydns.fr',
)
preferences:
182.67 ms | 402 KiB | 150 Q