3
I did a function that takes several arguments, and I decided to pass them by a array
to be executed. Ex:
public function funcTeste(array $dados){
return \count($dados);
}
But this array must have a default number of keys (as if I said $dados = ['key1', 'key2', 'key3']
, or something like).
More than that, if this array has parameters not passed (as if the user passes as parameter ['key1' => 'cavalo', 'key2' => 'avestruz']
) there is a way in the function to fill this value with a default
?
I am using PHP 7.1.23
If you need it to be a set value with default values, why did you use the array and did not define the arguments separately?
– Woss
I thought it would be easier to pass the parameters, especially in functions with
n
required parameters, where, if changing the order of two of them, breaks the entire calculation– Arthur Siqueira
I’m not sure if there’s what I’m looking for, but if there is, it’ll be a hand on the wheel
– Arthur Siqueira
You will have to make the conditions within the function to ensure what you need.
– Woss