[ create a new paste ] login | about

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

PHP, pasted on May 28:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
class SessionAccessor {
    static $test = array('sample' => array(1,2,3));
    static function &getVar($str) {
        $arr =& self::$test;
        foreach(explode('/',$str) as $path){
            $arr =& $arr[$path];
        }
        return $arr;
    }
}

$sample =& SessionAccessor::getVar('sample/1');
$sample = 'new value';

var_dump(SessionAccessor::$test);


Output:
1
2
3
4
5
6
7
8
9
10
11
array(1) {
  ["sample"]=>
  array(3) {
    [0]=>
    int(1)
    [1]=>
    &string(9) "new value"
    [2]=>
    int(3)
  }
}


Create a new paste based on this one


Comments: