The js function has an array arguments that stores parameters, therefore, functions supporting default parameter values in js can be implemented in php using another work ing method. It is convenient to set the default value for parameters when defining a function, for example:
The Code is as follows:
Function simue ($ a = 1, $ B = 2 ){
Return $ a + $ B;
}
Echo simue (); // output 3
Echo simue (10); // OUTPUT 12
Echo simue (10, 20); // output 30
But JavaScript cannot be defined as this. If function simue (a = 1, B = 2) {} is written, a message indicating a missing object is displayed.
The js function contains an array arguments for storing parameters. All parameters obtained by the function are saved to this array by the compiler one by one. Therefore, the js version supports the default parameter values. You can use another work und to modify the preceding example:
The Code is as follows:
Function simue (){
Var a = arguments [0]? Arguments [0]: 1;
Var B = arguments [1]? Arguments [1]: 2;
Return a + B;
}
Alert (simue (); // output 3
Alert (simue (10); // OUTPUT 12
Alert (simue (10, 20); // output 30