On Mon, 7 Jul 2003 23:37:58 +0100, you wrote: >On Mon, Jul 07, 2003 at 06:20:42PM +0100, David Otton wrote: >> On Mon, 7 Jul 2003 17:36:26 +0100, you wrote: >> >> >I want to write a function (as I have written in several other languages) that >> >obtains it's arguments dynamically (using func_get_arg()) and then assigns to that >> >argument. Think of the way that scanf() works -- that sort of thing. >> > >> >I have distilled what I want to do in the code below. foo adds 1 to all of it's >> >arguments. >> > >> >function foo () { >> > $count = func_num_args(); >> > for($i = 0; $i <= $count; $i++) { >> > $var = func_get_arg($i); >> > // The following line should do it, but throws a syntax error >> > &$var = $var + 1; >> > } >> >} >> > >> >$a = '1'; >> >$b = '2'; >> >$c = '3'; >> > >> >foo($a, $b, $c);
>> But I get the feeling you're trying to modify the elements in-place? Any >> particular reason? >> >> If it's because you want to return multiple values from the function, >No, the reason that I want to do it is for the same reason that sscanf() does it -- I >want >to change the values of the variables that are passed to it. So you really do want to modify the variables in-place? Well ok, it's your code. The only way to do this (from within PHP), AFAIK, is to shoehorn a non-variable argument in there by passing the variables as an array. <? function foo($args) { array_walk ($args, create_function ('&$a','$a++;')); } $a = 1; $b = 2; $c = 3; foo (array (&$a, &$b, &$c)); echo ("$a, $b, $c"); ?> *shudder*. The other option is to write in C and bolt it on as a custom extension. (BTW, my first example used func_get_arg() in a loop to build an array when I really should have used func_get_args().) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php