The difference between passing variable parameters to functions in JS and PHP is the instance code. For more information, see. # JS call function to pass variable parameters
The code is as follows:
Script
Function test (){
For (var I = 0; I <arguments. length; I ++ ){
Alert (arguments [I]);
}
}
// Call a function
Test (1, 2, 3, 'ABC ');
Script
# PHP call the function to pass variable parameters
The code is as follows:
// Method 1
// Receives a series of parameters and outputs them one by one
Function show_params (){
// Obtain the number of passed parameters
$ Count = func_num_args ();
// Traverse parameters and output them one by one
For ($ I = 0; $ I <$ count; $ I ++ ){
// Obtain parameters
$ Param = func_get_arg ($ I );
Echo $ param. PHP_EOL;
}
}
// Call a function
Show_params (1, 2, 'apple', 3.14 );
// Method 2
Function show_params (){
// Define an array for storing passed parameters
$ Params = array ();
// Obtain all parameters
$ Params = func_get_args ();
$ Count = count ($ params );
// Traverse and output parameters one by one
For ($ I = 0; $ I <$ count; $ I ++ ){
Echo $ params [$ I];
Echo PHP_EOL;
}
}
// Note: Method 2 is slower than method 1.