NYCPHP Meetup

NYPHP.org

[nycphp-talk] talk Digest, Vol 29, Issue 24

Douglas Clifton dwclifton at gmail.com
Sat Oct 15 22:57:39 EDT 2005


Or you can pass the arguments as an array, and
then decompose them for use inside the function:

function my_function($args)  {
  foreach ($args as $arg) trim($arg);
  list($arg1, $arg2, $arg3) = $args;
}

Or pass an associative array to the function with
the keys being the names of the individual arguments
and decompose them as variable variables:

foreach ($args as $name => $value) $$name = trim($value);

This would also be useful if you want the function to
process a variable number of arguments

There are countless ways of doing this sort of thing,
it might help if you explained in more detail what the
data and the function is trying to accomplish. --doug

> ---------- Forwarded message ----------
> From: robyn o <robynover at gmail.com>
> To: talk at lists.nyphp.org
> Date: Fri, 14 Oct 2005 14:10:23 -0400
> Subject: [nycphp-talk] all functions parameters in an array?
> Is there a php function to get all the parameters in a user function in an
> array?
>
>  For example, I have several strings in a function, and I'd like to do the
> same thing to all of them before I deal with them individually:
>
>  function my_function($a, $b, $c, $d){
>        foreach ($array_of_parameters as $p){
>             $p = trim($p);
>        }
>  }

--
Douglas Clifton
dwclifton at gmail.com
http://loadaveragezero.com/
http://loadaveragezero.com/app/s9y/
http://loadaveragezero.com/drx/rss/recent



More information about the talk mailing list