php - Is there a way to specify only some optional function args? -
i have function
public function test($arg1, $arg2 = "a", $arg3 = "b")
is there way call specifying $arg1
, $arg3
leaving $arg2
default value?
function test($arg1, $arg2 = "a", $arg3 = "b") { if (is_null($arg2)) $arg2 = "a"; return $arg1.' '.$arg2.' '.$arg3; } echo test(1, null, 3);
output:
1 3
will point out in javascript quite common:
function test (input, callback) { $.post( "example.com/endpoint", input, function(err, data) { if (error || response.statuscode !== 200) { callback(true, response) } callback(null, data) }) } test({ 'id': 1, 'name': 'mary' }, function (err, data) { if (err) { console.log.error('error!!') console.log(data) } console.log.info(data) })
That was superb information you shared! It was very relatable. I also started my freelancing career six months ago at Eiliana.com. Some ample clients are actually trying hard to Hire a programmer, and I am quite lucky to find a highly interesting project for me.
ReplyDelete