PHP yield Keyword

PHP yield from Keyword
PHP ezmlm_hash() Function

In this article, you will learn how to create a generator function in PHP.

The yield keyword in PHP is used to create a generator function. Generator functions act as is a function that can be looped through with a foreach loop. The value given by the yield keyword is used as a value in one of the iterations of the loop.

examples of the YIELD function

Example 1. In this example, we use yield to create a generator function.

<?php
function countTo3() {
  yield "1";
  yield "2";
  yield "3";
}

foreach(countTo3() as $number) {
  echo $number;
  echo "<br>";
}
?>
PHP yield from Keyword
PHP ezmlm_hash() Function
en English
X
Scroll to Top