I'm having a problem with the parameters in a PHP function.
For example:
function exemplo($par1 = 1, $par2 = 2) {
return $par1 . " - " . $par2;
}
exemplo(); // 1 - 2
exemplo(3); // 3 - 2
exemplo(3, 4); // 3 - 4
exemplo(null, 4); // - 4
In the last call, I'm trying to pass only the second parameter and keep the first as default , but not what happens (variable gets value null
).
Is it possible to achieve the desired behavior in this case?