-Zeus- Posted March 15, 2009 Share Posted March 15, 2009 Hi, I'm new to PHP, so bear with me if this is common knowledge. I did a search and could find no pertinent information. I currently have a script run by <?=shell_exec('script.sh arg1 arg2 arg3')?>, and i want to change it to a function, script(arg1 arg2 arg3). However, everything about functions I have seen so far requires that you name the variables in the header. I am looking for something independant of the number of variables - e.g., function script($*) { echo shell_exec('script.sh $*'); } Is this possible? I think it must be. Quote Link to comment https://forums.phpfreaks.com/topic/149475-pass-all-variables-in-function/ Share on other sites More sharing options...
.josh Posted March 15, 2009 Share Posted March 15, 2009 function someFunc () { // example 1: $count = func_num_args(); for ($x = 0; $x < $count; $x++) { echo "Argument $x : " . func_get_arg($x) . "<br/>"; } // example 2: $args = func_get_args(); foreach ($args as $n => $v) { echo "Argument $n : $v"; } } someFunc(); someFunc(100); someFunc('abc',123); someFunc(1,true,"omg",'x',1234,$blah); Quote Link to comment https://forums.phpfreaks.com/topic/149475-pass-all-variables-in-function/#findComment-785003 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.