Home  >  Article  >  Backend Development  >  Can php pass array parameters?

Can php pass array parameters?

青灯夜游
青灯夜游Original
2022-05-09 18:35:012512browse

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}".

Can php pass array parameters?

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);
?>

Can php pass array parameters?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn