Generator::key
(PHP 5 >= 5.5.0)
Generator::key — Get the yielded key
Description
Warning
This function is currently not documented; only its argument list is available.
Parameters
This function has no parameters.
Return Values
Returns the yielded key.
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник языка
- Встроенные интерфейсы и классы
- Функция Generator::current() - Get the yielded value
- Generator::getReturn
- Функция Generator::key() - Get the yielded key
- Функция Generator::next() - Resume execution of the generator
- Функция Generator::rewind() - Rewind the iterator
- Функция Generator::send() - Send a value to the generator
- Функция Generator::throw() - Throw an exception into the generator
- Функция Generator::valid() - Check if the iterator has been closed
- Функция Generator::__wakeup() - Serialize callback
Коментарии
This is important when considering how other Generators work such as JavaScript's an Python's. While PHP's generator has the ->valid() method they don't, or an equivalent. JS uses Iterator protocol which says next() should return an object of
{
done: bool,
value: mixed
}
In which case you can use keys->done to see if the generator can still be iterated.