- json_decode: documentation ( source)
- print_r: documentation ( source)
- array_shift: documentation ( source)
- array_keys: documentation ( source)
<?php
$key = array('accounts', 1, 'uid');
$conf = json_decode('{
"accounts": {
"1": {
"uid": "1"
},
"2": {
"uid": "16"
}
},
"online": [
{
"rules": {
"language": "pl"
},
"tag": {
"name" : "kraj",
"value": "Polska",
"save" : true,
"delay": 1800
}
}
]
}
', true);
if (!is_array($key)) {
$key = array($key);
}
if (!empty($key)) {
$chain = $conf;
foreach ($key as $k) {
if ($k == ':first:') {
$k = array_shift(array_keys($chain));
}
if (is_array($chain) && isset($chain[$k])) {
$chain = $chain[$k];
} else {
return false;
}
}
print_r($chain);
} else {
print_r($conf);
}