<?php
$data = [
'param' => [
'param1' => '...',
'param2' => [
'param3' => '...'
]
]
];
function data($d) {
global $data;
$a = explode('.', trim($d));
$c = count($a);
switch($c) {
case 1:
return $data[$a[0]] ?? '';
break;
case 2:
return $data[$a[0]][1] ?? '';
break;
case 3:
return $data[$a[0]][$a[1]][$a[2]] ?? '';
// ...
}
}
echo data('param.param2.param3');
$data = [
'param' => [
'param1' => '111',
'param2' => [
'param3' => '333'
]
]
];
function deep_get($arr, $keys, $default=False) {
return array_reduce(explode('.', $keys), function($d, $key){
if (is_array($d)) {
return $d[$key] ? $d[$key] : $default;
}else{
return $default;
}
},
$arr
);
}
echo deep_get($data, 'param.param2.param3');