Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

251
Vistas
PHP generator function explained

I am trying to get the logic of php generator functions, what i got so far is that is that a generator function is exactly like a normal function but you can use the keyword yield as many times as it needs to in order to provide the values to be iterated over. and this cannot be done by the return keyword .

is it like returning an array ?

where do we need generators ?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

A generator allows you to loop over a sequence of values without first creating an array to hold them all. This is useful if the sequence never ends (you use break to get out of the loop when some criteria is reached) or if it would take a long time or use lots of memory to create all the array elements.

Instead of collecting all the values into an array, the generator calculates each value as it's needed, and uses yield to produce this value.

There's an example in the documentation showing a variation of the range() function that uses a generator, so you can process very large ranges without using lots of memory.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda