> -----Original Message-----
> From: christian haines [mailto:[EMAIL PROTECTED]]
> Sent: 03 December 2002 13:32
> 
> 
> hi all,
> 
> is it possible to somehow have a function which takes a 
> variable number 
> of arguments

Yes -- look at the manual pages for func_num_args (http://www.php.net/func-num-args) 
and func_get_arg (http://www.php.net/func-get-arg).

>  (with some kind of key association)

No.

> i am sick of continually having to go back and add empty 
> parameters to 
> functions in use.

Why don't you just make the extra parameters optional? As in:

   function test1($test, $this=NULL) {
      if (isset($this)):
         echo "\$this was passed with value $this";
      else:
         echo "\$this was not passed";
      endif;
   }

> function test2($arr)
> {
>     extract($arr);
>     print $this;
> }
> 
> test2($arr = array(
> "test" => 1,
> "this" => 2
> ));
> // output
> 2
> 
> is there another ... better or cleaner way?

If you want "named" parameters, this is pretty much how to go about it -- except that 
the function call doesn't need the "$arr =", so could be written more cleanly as:

   test2( array('test'=>1, 'this'=>2) );

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to