By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,197 Members | 1,057 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,197 IT Pros & Developers. It's quick & easy.

trivial arguments function

P: n/a
hi all

i've a function F as

function F($arg1,$arg2,$arg3){
....
}

and a variable $args = "A,B,C"

my goal is to call the function with the content of $args.

if i call f($args) i call this function with 1 argument : an array, i
wish call function as f(A,B,C)

If Someone thinks this is possible... please give me the code ;))

regards.

Jul 13 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
jh****@gmail.com wrote:
hi all

i've a function F as

function F($arg1,$arg2,$arg3){
...
}

and a variable $args = "A,B,C"

my goal is to call the function with the content of $args.

if i call f($args) i call this function with 1 argument : an array, i
wish call function as f(A,B,C)

If Someone thinks this is possible... please give me the code ;))

regards.
f($args[0]. $args[1], $args[2]);

Or -
f($arg1, $arg2=null, $arg3=null) {
if (is_array($arg1) && $arg2==null && $arg3 == null) {
if (count($arg1) == 3)
$arg2 = $arg1[1];
$arg3 = $arg1[2];
$arg1 = $arg1[0];
}
else {
echo "Insufficient number of parameters passed<br>\n";
exit();
}
}
... rest of stuff here
}

Of course you should do other checking to ensure you're passing 3
arguments in the array.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 13 '06 #2

P: n/a

jh****@gmail.com wrote:
hi all

i've a function F as

function F($arg1,$arg2,$arg3){
...
}

and a variable $args = "A,B,C"

my goal is to call the function with the content of $args.

if i call f($args) i call this function with 1 argument : an array, i
wish call function as f(A,B,C)

If Someone thinks this is possible... please give me the code ;))

regards.
call_user_func_array('F', explode(',' $args));

Jul 13 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.