If I have a function like this:
function abc($a,$b,$c = 'foo',$d = 'bar') { ... }
And I want $c to assume it’s default value, but need to set $d, how would I go about making that call in PHP?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
PHP can’t do this, unfortunately. You could work around this by checking for null. For example:
Then you’d call the function like this:
No, it’s not exactly pretty, but it does the job. If you’re feeling really adventurous, you could pass in an associative array instead of the last two arguments, but I think that’s way more work than you want it to be.