[ create a new paste ] login | about

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

PHP, pasted on Aug 26:
<?php

$array = array(
   'a' => array( 'b' => array( 'c' => 'value') ),
   'b' => array( 'a' => 'value' ),
);

function override($array, $value) {
	$args = func_get_args();
	$array = array_shift($args);
	$value = array_shift($args);
	$set = &$array;
	while(count($args))
	{
		$key = array_shift($args);
		$set = &$set[$key];
	}
	$set = $value;
	unset($set);
	return $array;
}

var_dump(override($array, 'new', 'a', 'b', 'c'));


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
array(2) {
  ["a"]=>
  array(1) {
    ["b"]=>
    array(1) {
      ["c"]=>
      string(3) "new"
    }
  }
  ["b"]=>
  array(1) {
    ["a"]=>
    string(5) "value"
  }
}


Create a new paste based on this one


Comments: