Home  >  Article  >  Backend Development  >  QQ space background music player code Difference between JS and PHP in passing variable parameters to functions Example code

QQ space background music player code Difference between JS and PHP in passing variable parameters to functions Example code

WBOY
WBOYOriginal
2016-07-29 08:45:141158browse

# JS method of calling functions to pass variable parameters

Copy code The code is as follows:


<script> <br>function test() { <br>  for(var i = 0;i < arguments.length; i++ ) { <BR>  alert(arguments[i]); <BR> } <BR>} <BR>//Call function <BR>test(1, 2, 3, 'abc'); <BR></script>


# PHP calls function passing variable Parameter method

Copy codeThe code is as follows:


   //Method 1
  //Receive a series of parameters and output them one by one
  function show_params () {
    // Get the passed parameters Number
  $count = func_num_args();
   //Traverse the parameters and output them one by one
   for ($i = 0; $i < $count; $i++) {
     //Get the parameters
   $param = func_get_arg($i ); C Echo $ Param. PHP_EOL;
}}}
// Call the function
show_params (1, 2, 'apple', 3.14); Array of
  $params = array();
   //Get all parameters
  $params = func_get_args();
  $count = count($params); $i < $count; $i++) {
   echo $params[$i];
   echo PHP_EOL;
  }
  }
 //Note: Method 2 executes slower than method 1


The above has introduced the qq space background music player code and the difference between JS and PHP in passing variable parameters to functions. The example code includes the content of the qq space background music player code. I hope it will be helpful to friends who are interested in PHP tutorials.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn