Look at a piece of code first
function concatenate($transform, ...$strings) { $string = ''; foreach($strings as $piece) { $string .= $piece; } return($transform($string)); } echo concatenate("strtoupper", "I'd ", "like ", 4 + 2, " apples");
When the function is defined, use... Operator to indicate that this is a variable parameter, if you pass If 2 or more parameters are provided, these parameters will be added to this array.
Argument Unpacking
This is a function that echoes the above function.
Variadic functions allow you to declare the incoming parameter array, and parameter unpacking allows you to pass an array to a function and automatically unpack it inside the function. The example is as follows:
$email[] = "Hi there"; $email[] = "Thanks for registering, hope you like it"; mail("someone@example.com", ...$email);
You can put Put all the parameters in an array, and PHP will handle it all for you :)
The above is the detailed content of What are php variable parameters?. For more information, please follow other related articles on the PHP Chinese website!