PHP function variable number of argument list

Source: Internet
Author: User
This article introduces you to the PHP function variable number of parameter list, the need for friends can refer to

PHP5.5 and earlier versions

Use the following function:

  • func_num_argsReturns the total number of parameters

  • func_get_argReturns an item of a parameter list

  • func_get_argsReturns an array containing a list of function arguments

function test () {    echo ' parameter total; ', Func_num_args (), ' \ n ';    echo ' first parameter: ', Func_get_arg (0), ' \ n ';    echo ' all parameters; ';    Print_r (Func_get_args ());} Test (1, 2, 3, 4);/* Total number of parameters, 4 first parameter: 1 all parameters; Array (   [0] = 1   [1] = 2 [   2] = 3   [3] = 4) */

Version PHP5.6 and above

Using ... syntax to implement

Function Test (... $params) {    print_r ($params);} Test (1, 2, 3, 4);/*array         (                 [0] = 1      [1] = 2      [2] = 3      [3] = 4  ) */
Related Article

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.