How to input an indefinite number of parameters to a php function?

Source: Internet
Author: User
The simplest way to input an indefinite number of parameters in a php function is to input an array. the number of array values can be unlimited.

How to input an indefinite number of parameters to a php function?

I think there are two methods.

  • Input values in array mode

  • The function obtains the value through func_get_args.


The simplest way is to input an array. the number of array values can be unlimited.

Another method is to use func_get_args to obtain parameters.


Function args ($ SQL) {$ args = func_get_args (); array_shift ($ args); var_dump ($ SQL ); // 'all arguments in one array' syntax if (isset ($ args [0]) and is_array ($ args [0]) {$ args = $ args [0];} var_dump ($ args);} args ($ SQL = 1, $ query = 3, $ db = 'Lee '); args (array ('SQL' => 1, 'query' => 3, 'DB' => 'Lil '));
The output of the input parameter is as follows:

Int (1) array (2) {[0] => int (3) [1] => string (3) "lee"} array (3) {["SQL"] => int (1) ["query"] => int (3) ["db"] => string (3) "lee"} array (0 ){}

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.