- iterator_to_array: documentation ( source)
<?php
function yieldMe() : iterable
{
yield 1;
yield 2;
yield 3;
}
function someFunction(bool $toArray=true) : iterable
{
$found = yieldMe();
if($toArray){
return iterator_to_array($found);
}
yield from $found;
}
$result = someFunction();
foreach($result as $r){
echo $r."\n";
}