Php variable length parameter processing functions

Source: Internet
Author: User
This article mainly introduces php variable length parameter processing functions, and analyzes the functions and usage of three variable length parameter processing functions, func_num_args (), func_get_arg (), and func_get_args (), in combination with examples, for more information about php variable length parameter processing functions, see the example in this article. We will share this with you for your reference. The details are as follows:

Like C ++, PHP can also process functions that contain variable parameters. The truth is the same. a function is required to process the parameter list. PHP provides three related functions:

1. func_num_args () -- Returns the number of parameters passed to the function.

int func_num_args ( void )

Example:

function open_database($DB, $cache_size_or_values=null, $cache_size=null){  switch (function_num_args())  {    case 1:      $r = select_db($DB);      break;    case 2:      $r = select_db($DB, $cache_size_or_values);      break;    case 3:      $r = select_db($DB, $cache_size_or_values, $cache_size);      break;  }  return is_resource($r);}

2. func_get_arg () -- Return the specified parameter

mixed func_get_arg ( int arg_num)

The arg_num of the first parameter in the parameter list is 0.

 

3. func_get_args () -- returns the parameter list as an array.

array func_get_args ( void )

Example:

 

For more details about php variable length parameter processing functions, refer to the PHP Chinese network!

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.