# JS calls a function to pass a variable parameter method
Copy Code code as follows:
<script>
function Test () {
for (var i = 0;i < Arguments.length; i++) {
Alert (Arguments[i]);
}
}
Call function
Test (1, 2, 3, ' abc ');
</script>
# PHP calls a function to pass a variable parameter method
Copy Code code as follows:
<?php
//Method one
///Receive a series of parameters and output
function Show_params () {
//Get the number of pass parameters
$count = Func_num_args ();
//traversal parameters and output each
for ($i = 0; $i < $count; $i + +) {
//Get parameters
$param = func_get_ Arg ($i);
Echo $param. Php_eol;
}
}
//Call Function
Show_params (1, 2, ' Apple ', 3.14);
//Method 2
Function Show_params () {
//define array of Store pass parameters
$params = arrays ();
//Get all parameters
$params = Func_get_args ();
$count = count ($params);
//traversal and output parameters
for ($i = 0; $i < $count; $i + +) {
echo $params [$i];
Echo Php_eol;
}
}
//Note: Method 2 is slower to perform than Method 1