I have a problem with creating a dynamic assoc array based on a string.
For example the following piece of code:
Session::addSession('browser.history','stackoverflow');
This should return the following array: $_SESSION[TL_MODE]['browser']['history'] = 'stackoverflow';
Current addSession function:
public static function addSession($type, $value) {
$_SESSION[TL_MODE][$type] = $value;
}
I have been working on this for a couple of days and I still don't have a solution.
I hope someone could help me solve this problem, or if my approach is just wrong, I would like to know how I can achieve the same goal with a different approach.
---UPDATE---
Thanks to someone who saw this was a duplicated question. This is how I fixed it for my situation:
$temp = &$_SESSION[TL_MODE];
$exploded = explode('.', $path);
foreach($exploded as $key) {
if(!is_array($temp[$key])) {
$temp[$key] = array();
}
$temp = &$temp[$key];
}
$temp[] = $value;
unset($temp);