Connecting Tech Pros Worldwide Forums | Help | Site Map

Re: getting parameters to send then to another function

FutureShock
Guest
 
Posts: n/a
#1: Sep 23 '08
Newsgroups wrote:
Quote:
Hi, I'm trying something...
>
My goal is to have a unique function with undeterminated number of
parameters witch return the sprintf result.
>
<?php
print test("key", "key2");
function test($k)
{
return sprintf("test %s %s", $k);
}
?>
>
So, in this case, when we are calling test() function, we need 2 parameters
because sprintf require 2 "%s"...
but I don't know how to send the test() parameter's into the sprintf's ones
...
>
Do you understand ? ansd do you have any solution ? thanks.
>
>
>
Your best bet would probably be to pass the function an array of your
variables and then extract them inside the function for use.

Remember that you have to pass the same number of parameters into the
function as what it was designed for.

Your function above would fail as the $key2 would not make it inside the
function.

Scotty

Closed Thread