You know how PHP's isset()
can accept multiple (no limit either) arguments?
Like I can do:
isset($var1,$var2,$var3,$var4,$var5,$var6,$var7,$var8,$var9,$var10,$var11);
//etc etc
How would I be able to do that in my own function? How would I be able to work with infinity arguments passed?
How do they do it?
Starting with PHP 5.6 you can use the token "..."
Example:
Source: http://php.net/manual/en/functions.arguments.php#functions.variable-arg-list
func_get_args
will do what you want:You can also use
func_get_arg
to get a specific parameter (it's zero-indexed):But be careful to check that you have that parameter:
You can even mix together
func_*_arg
and regular parameters:But before using it, think about whether you really want to have indefinite parameters. Would an array not suffice?
You can use
func_get_args()
, it will return an array of arguments.Calling
func_get_args()
inside of your function will return an array of the arguments passed to PHP.