Search code examples
phpamphp

Create Iterator from array with AMPHP


I have an array in php:

$array = [1,2,3];

When I do:

while(yield $array->advance())

I get Call to a member function advance() on array

How do I turn my array into an iterator?


Solution

  • You can call ->advance() only on instances of Amp\Iterator.

    So you need to convert your basic php array first with the fromIterable method.

    Amp\Iterator\fromIterable($array)