I have a function with a non-defined size. Also, I have a function which received an unlimited number of arguments that represent the desired result's indexes. I want this function to return the value of the array, which those indexes related to.
In order to retrieve the data, I've built the following function:
public static function get() {
$result = self::$config; // $config is the unknown sized array
$args = func_get_args();
foreach($args as $arg) {
$result = $result[$arg];
}
return $result;
}
However, I didn't manage to build a "set" function.
How can I edit the source array ($config), based on the parameters inserted?
Example:
We have the following array:
$ron = array(
'first' => array('inside' => 1),
'second' => array('inside' => array('anotherInside' => 2),
'lol' => 'lol'
),
'third' => 3
);
Now we are activating the function with the parameters as follows:
function retrieve('newValue', 'second', 'inside');
The function should edit the source to:
$ron = array(
'first' => array('inside' => 1),
'second' => array( **'inside' => 'newValue',**
'lol' => 'lol'
),
'third' => 3
);
Thanks