1

I have a function

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

I want to add all this in array by array_push is there a variable enable me do this in one step.

I want echo all this on ($a,$b,$c,$d) by foreach

I don't know it i will assume any variable 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 and I cant explain because I don't understand

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

I want foreach all variables between () OK in function**(void)**{

1
  • You should rewrite your question. I read it twice and found it extremely difficult to understand. Notice how I have used fullstop... you can also use commas in your question. Commented Feb 23, 2010 at 11:02

4 Answers 4

4

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);
Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

1

func_get_args() returns all arguments passed to the function.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.