Yield Or Return¶
<?php
function foo() {
yield 1;
yield 2;
yield 3;
return ['a', 'b', 'c'];
}
function foo2() {
return ['a', 'b', 'c'];
}
function goo($x, $y, $z) {
print "$x $y $z\n";
}
goo(...foo());
goo(...foo2());
It is possible to spread an array as dynamic arguments: this applies to returned arrays, after a function call.
The function call may be actually of two types: function or a generator.
The first type is a generator: then, the yielded values are used as argument and the returned array is ignored.
In the second case, the array is returned and used.
See Also¶
Array or yield? [Try me]
PHP Features¶
Last updated: 14 July 2026