The difference instance code between JS and PHP passing variable parameters to a function

Source: Internet
Author: User
# JS Call function method for passing variable parameters

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

How PHP calls functions to pass mutable parameters

<?php//Method One//receive a series of parameters and output function Show_params () {//Get the number of pass parameters $count = Func_num_args ();       Traverse parameters and output each for ($i = 0; $i < $count; $i + +) {//get parameter $param = Func_get_arg ($i); Echo $param.     Php_eol;   }}//Call function Show_params (1, 2, ' Apple ', 3.14);     Method 2 function Show_params () {//defines an array of stored pass parameters $params = Array ();     Get all parameters $params = Func_get_args ();     $count = count ($params);       Iterate and output parameters for ($i = 0; $i < $count; $i + +) {echo $params [$i];     Echo Php_eol; }}//Note: Method 2 performs slower than Method 1

Related articles:

How does PHP pass each element of an array as an argument to a mutable parameter function?

PHP variable parameters

PHP variable parameter implementation

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.