Skip to content

Instantly share code, notes, and snippets.

@mgsmus
Last active December 8, 2019 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgsmus/dca0209d685c4a4f115e13caef283855 to your computer and use it in GitHub Desktop.
Save mgsmus/dca0209d685c4a4f115e13caef283855 to your computer and use it in GitHub Desktop.
<?php
$arr1 = [1, 2, 3];
$arr2 = […$arr1]; //[1, 2, 3]
$arr3 = [0, …$arr1]; //[0, 1, 2, 3]
$arr4 = array(…$arr1, …$arr2, 111); //[1, 2, 3, 1, 2, 3, 111]
$arr5 = […$arr1, …$arr1]; //[1, 2, 3, 1, 2, 3]
function getArr() {
return ['a', 'b'];
}
$arr6 = […getArr(), 'c']; //['a', 'b', 'c']
$arr7 = […new ArrayIterator(['a', 'b', 'c'])]; //['a', 'b', 'c']
function arrGen() {
for($i = 11; $i < 15; $i++) {
yield $i;
}
}
$arr8 = […arrGen()]; //[11, 12, 13, 14]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment