mirror of
https://github.com/igorsimdyanov/php8.git
synced 2025-08-13 14:45:09 +00:00
15 lines
262 B
PHP
15 lines
262 B
PHP
<?php
|
|
function square($value)
|
|
{
|
|
yield $value * $value;
|
|
}
|
|
|
|
function even_square($arr) {
|
|
foreach($arr as $value) {
|
|
if ($value % 2 == 0) yield from square($value);
|
|
}
|
|
}
|
|
|
|
$arr = [1, 2, 3, 4, 5, 6];
|
|
foreach(even_square($arr) as $val) echo "$val ";
|