Using func_get_args to edit an array

508029680

New Member
I wish to use a function with an arbitrary number of arguments to edit an array. The code I have so far is:\[code\] function setProperty() { $numargs = func_num_args(); $arglist = func_get_args(); $toedit = array(); for ($i = 0; $i < $numargs-1; $i++) { $toedit[] = $arglist[$i]; } $array[] = $arglist[$numargs-1]; }\[/code\]The idea of the code being I can do the following:\[code\]setProperty('array', '2nd-depth', '3rd', 'value1');setProperty('array', 'something', 'x', 'value2');setProperty('Another value','value3');\[/code\]Resulting in the following array:\[code\]Array( [array] => Array ( [2nd-depth] => Array ( [3rd] => value1 ) [something] => Array ( [x] => value2 ) ) [Another Value] => value3)\[/code\]The issue I believe is with the line: \[code\]$toedit[] = $arglist[$i];\[/code\]What does this line need to be to achieve the required functionality?Cheers,
 
Back
Top