- var_dump: documentation ( source)
- phpversion: documentation ( source)
- version_compare: documentation ( source)
<?php
function yieldAll(array $total)
{
if (!version_compare(phpversion(), '5.5.0', '>=') && !defined('HHVM_VERSION')) {
throw new DomainException(__FUNCTION__.' works only with a PHP version that supports Generators');
}
foreach ($total as $key => $value) {
$stmt = (yield $key => $value);
if (! $stmt) {
return;
}
}
}
$toto = [];
$res = yieldAll(['toto', 'tata', 'tutu']);
foreach ($res as $key => $value) {
if (1 == $key) {
$res->send(false);
}
$toto[$key] = $value;
}
var_dump($toto);