Reputation: 39456
A simple question:
What is the syntax for creating a function with unlimited* arguments in PHP?
Example (ActionScript 3):
function multiTrace(...arguments):void
{
var i:String;
for each(i in arguments)
trace(i);
}
The goal is to have a function that I can call and list any given amount of stylesheets within, eg:
$avian->insertStyles("overall.css", "home.css");
*Subject to obvious limitations (RAM, etc).
Upvotes: 2
Views: 118
Reputation: 8046
See
http://nl.php.net/manual/en/function.func-get-args.php
function testfunction() {
$arguments = func_get_args();
var_dump($arguments);
}
testfunction("argument1", "argument2");
Result:
array
0 => string 'argument1' (length=9)
1 => string 'argument2' (length=9)
Upvotes: 3
Reputation: 10764
function multiTrace()
{
$args = func_get_args();
while ($arg = array_shift($args)) {
echo $arg;
}
}
see: http://php.net/manual/en/function.func-get-args.php
Upvotes: 7
Reputation: 16236
I think you are after the func_get_args function:
http://php.net/manual/en/function.func-get-args.php
Upvotes: 1