Php function usage with variable number of defined parameters _ PHP Tutorial

Source: Internet
Author: User
Php defines a variable number of function usage instances. Example of function usage with variable number of php defined parameters this article mainly introduces the function usage with variable number of php defined parameters. The example shows how to use func_get_args, examples of function usage with variable number of parameters defined by reference to php

This article mainly introduces the usage of php functions with variable number of defined parameters. The example analyzes the usage skills of func_get_args, which has some reference value. For more information, see

This example describes how to use a function that defines variable number of parameters in php. Share it with you for your reference. The specific analysis is as follows:

The function parameters in php can be unfixed or even need not be defined. in the function, use the func_get_args () function to obtain the parameter list. you can specify any parameter for the function during the call, which is very convenient.

?

1

2

3

4

5

6

7

8

9

10

11

12

13

Function addanything (){

$ Total = 0;

$ Args = func_get_args ();

For ($ I = 0; $ I <count ($ args); $ I ++ ){

If (is_int ($ args [$ I]) {

$ Total + = $ args [$ I];

}

}

Return $ total;

}

Echo addanything (1, 5, 7, 8, 11 )."
";

?>

I hope this article will help you with php programming.

This article describes how to use a function that defines variable number of parameters in php. The example analyzes the usage skills of func_get_args...

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.