PHP Spread Syntax in Array Declaration

后端 未结 4 880
遇见更好的自我
遇见更好的自我 2020-12-14 15:40

PHP supports the spread syntax for variadic functions.

In JavaScript, you can use the spread syntax to do this:

var a = [1, 2];
var b = [...a, 3, 4];         


        
4条回答
  •  一整个雨季
    2020-12-14 16:14

    In PHP 7.4 you can now use Spread Operators in array expressions.

    $parts = ['apple', 'pear'];
    $fruits = ['banana', 'orange', ...$parts, 'watermelon'];
    // ['banana', 'orange', 'apple', 'pear', 'watermelon'];
    

提交回复
热议问题