So I have a string $key which is something along the lines of system.style.background which I explode at character '.' to $exp. I also have some decoded JSON $system.
I would like to do something like this
echo $system[$exp[0]][$exp[1]][$exp[2]]
which would be
echo $system["system"]["style"]["background"]
However, $key could be any string, with n amount of delimiters. Such as
- system
- system.style
- system.style.background
- system.style.background.description
How would I write a function that takes a string and returns the json value like above?
Edit: A jank way of doing it would be
if(isset($exp[0])){
$config[$exp[0]];
}
if(isset($exp[1])){
$config[$exp[0]][$exp[1]];
}
if(isset($exp[n])){
$config[$exp[0]][$exp[1]][$exp[n]];
}
Edit: Not duplicate because this is an associative array