How would you refer to the parameter with the value cat in the following
function?
<?php
function complicated($compulsory, ...$extras, $animal) {
// I want to reference the variable with the value "cat"
}
complicated(1,2,3,"cat");
Fatal error: Only the last parameter can be variadic
Correct:
Fatal error: Only the last parameter can be variadic
Explanation:
This feature allows you to capture a variable number of arguments to a function, combined with "normal" arguments passed in if you like. It's easiest to see with an example:
The parameters list in the function declaration has the ... operator in it, and it basically means " ... and everything else should go into $strings". You can pass 2 or more arguments into this function and the second and subsequent ones will be added to the $strings array, ready to be used.