I want to destructure an array of values into function named parameters and not care about the array value order.
example:
$functionParams = [$name, $lastname, $age, $randomparam];
function x($age, $name, $randomparam, $lastname){
}
x(...functionParams);
this wont work, because it doesnt have the same order,
I would like my destructuration to fit something like named parameters, as
x(...functionParams) -> x(name: $name, lastname: $lastname, age: $age, randomparam: $randomparam)
is there any way to achieve this ? Sorry if my explanation isnt propper
$functionParamsdoesn't know the variable name of the data given to it; in the same way a person in a restaurant doesn't know the name of the dish the chef presents to them, they only can see the ingredients, not what the ingredients combined together are called. So your array doesn't know the$ageitem, it knows the age value but not that this is the age. Solution: Use a named array key and pass that to the function to process.