tags:

views:

45

answers:

4

assume i have function

 function me($a,$b,$c,$d){

 }

and i want add all this in array by array_push is there a varible enable me do this in one step

and i i want echo all this on ($a,$b,$c,$d) by foreach now i dont know it i will assume any varible in () will equal $anything function me($a,$b,$c,$d){ foreach ($anything as $key => $value){ echo $value;// i want return $a,$b,$c,$d values } } any one understand what i want i want foreach the function i cant explan becuase i dont understand

see

function(void){
foreach(void){}
}

i want foreach all varibles between () ok in function*(void)*{

+3  A: 

You could try func_get_args(). Calling that will give you an array (numerically indexed) containing all of the parameter values.

I don't really understand what you are asking, though.

jasonbar
+1  A: 

func_get_args() returns all arguments passed to the function.

Ignacio Vazquez-Abrams
+3  A: 

I guess that you are talking about variable number of arguments. This example below is from the php site and uses func_num_args to get the actual number of arguments, and func_get_args which returns an array with the actual arguments:

function me()
{
   $numargs = func_num_args();
   echo "Number of arguments: $numargs<br />\n";
   if ($numargs >= 2) {
       echo "Second argument is: " . func_get_arg(1) . "<br />\n";
   }
   $arg_list = func_get_args();
   for ($i = 0; $i < $numargs; $i++) {
       echo "Argument $i is: " . $arg_list[$i] . "<br />\n";
   }
}

me (1, 2, 3);
Martin Wickman
A: 

You can use func_get_args() like Jasonbar says:

function a() {
    foreach (func_get_args() as $param) {
        echo $param;
    }
}

a(1,2,3,4); // prints 1234
a(1,2,3,4,5,6,7); // prints 1234567
Tom Haigh