In java we call it overloading when we define two methods with different numbers of arguments.How do we do it in php or javascript开发者_开发问答 where number of parameters passed need not be equal to arguments defined.
Javascript:
function testing(){
console.log(arguments);//<-- all func args
}
PHP:
function testing(){
var_dump(func_get_args());//<-- all func args
}
You can assign default values to the parameters like so:
function example(a = 1, b = 2, c = 3) {
//Do something
}
example(10, 5);
精彩评论