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.