Home > Article > Backend Development > Can php pass array parameters?
php can pass array parameters. In PHP5.6 and later versions, the formal parameters of a function can use "..." to indicate that the function can accept a variable number of parameters, and the variable parameters will be passed to the function as an array, the syntax "function function Name(...$arr){//execution code}".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php can pass array parameters.
When calling a function, you need to pass parameters to the function. The parameters passed into the function are called actual parameters, and the parameters defined by the function are called formal parameters. There are four ways to pass parameters to a function, namely passing by value, passing by reference, default parameters and variable length parameters.
The variable length parameter will be passed to the function as an array.
PHP variable length parameters
In PHP 5.6 and later versions, the formal parameters of the function can be represented by …
The function can accept a variable number of arguments, which will be passed to the function as an array.
Examples are as follows:
<?php function test(...$arr){ var_dump($arr); } test(1, 2, 3, 4); test(5, 6, 7, 8, 9, 10); ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of Can php pass array parameters?. For more information, please follow other related articles on the PHP Chinese website!