[ create a new paste ] login | about

Link: http://codepad.org/j9nFiTiZ    [ raw code | output | fork ]

PHP, pasted on Feb 24:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php


    function assignArrayByPath(&$arr, $path, $value, $separator='.') {
        $keys = explode($separator, $path);
    
        foreach ($keys as $key) {
            $arr = &$arr[$key];
        }
    
        $arr = $value;
    }

$arr = array('test'=> false);
assignArrayByPath($arr, 'test.something', true);
var_dump($arr);


Output:
1
2
3
4
5
6
7
array(1) {
  ["test"]=>
  array(1) {
    ["something"]=>
    bool(true)
  }
}


Create a new paste based on this one


Comments: