PHP defines function usages with variable number of parameters

Source: Internet
Author: User
Tags php definition

This article mainly introduces the PHP definition parameter quantity variable function usage, the example analysis Func_get_args's use skill, has certain reference value, the need friend may refer to under

The examples in this article describe the functional usage of PHP's variable number of defined parameters. Share to everyone for your reference. The specific analysis is as follows:

PHP in the function parameters can not be fixed, or even the definition of parameters, within the function using the Func_get_args () function to obtain a list of parameters, call can specify any parameters for the function, very convenient

?
1 2 3 4 5 6 7 8 9 10 11 12-13 <?php 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). "<br/>";?>

I hope this article will help you with your PHP program design.

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.