PHP5.6 new variable function parameter Usage Analysis, php5.6 Function

Source: Internet
Author: User

PHP5.6 new variable function parameter Usage Analysis, php5.6 Function

This example describes the new variable function parameter usage in PHP5.6. We will share this with you for your reference. The details are as follows:

Today, I read the PHP manual. I found that PHP version updates have added many things. The variable function parameters added in the PHP5.6 update are described below.

Code 1:

Function sum (... $ numbers) {$ acc = 0; foreach ($ numbers as $ number) {$ acc + = $ number;} return $ acc;} echo sum (1, 2, 4 );

Result 1:

10

Code 1 parsing:

Method functions start from PHP5.6. function parameters can be omitted using three vertices. The passed parameters are operated as arrays in the function method.

Code 2:

Function sumNumber ($ a, $ B) {echo $ a + $ B; echo "\ n" ;}sumnumber (... [1, 2]); $ a = [1, 2]; sumNumber (... $ );

Code 2 result:

33

Code 2:

You can add arrays to three vertices during the call without affecting normal use.

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.