
Generator::current 속성은 Generator 객체의 현재 상태를 나타내는 속성입니다. Generator 객체는 반복 가능한 객체로, 반복을 통하여 값을 하나씩 꺼낼 수 있습니다. Generator::current 속성은 현재 Generator 객체에서 꺼낼 수 있는 다음 값을 반환합니다.
Generator::current 속성을 사용하는 경우에는 다음과 같은 예시가 있습니다.
#hostingforum.kr
php
function fibonacci() {
$a = 0;
$b = 1;
while (true) {
yield $a;
list($a, $b) = array($b, $a + $b);
}
}
$fib = fibonacci();
echo $fib->current() . "n"; // 0
echo $fib->current() . "n"; // 1
echo $fib->current() . "n"; // 1
echo $fib->current() . "n"; // 2
위의 예시에서, Generator::current 속성을 사용하여 Generator 객체에서 꺼낼 수 있는 다음 값을 반환할 수 있습니다.
2025-03-20 11:34