update page now
Laravel Live Japan

Voting

: max(five, three)?
(Example: nine)

The Note You're Voting On

bloodjazman at gmail dot com
12 years ago
for the protection from the leaking of resources 
see RFC https://wiki.php.net/rfc/generators#closing_a_generator

and use finnaly

sample code

function getLines($file) {
    $f = fopen($file, 'r');
    try {
        while ($line = fgets($f)) {
            yield $line;
        }
    } finally {
        fclose($f);
    }
}

foreach (getLines("file.txt") as $n => $line) {
    if ($n > 5) break;
    echo $line;
}

<< Back to user notes page

To Top