Generator::key
PHP function
Edit on GitHub ✎
(PHP 5 >= 5.5.0, PHP 7, PHP 8)
Get the yielded key
Description
Generator::key(): mixed
Gets the key of the yielded value.
Parameters Parameters
Return Values
Returns the yielded key.
Examples
Generator::key example
php
<?php
function Gen()
{
yield 'key' => 'value';
}
$gen = Gen();
echo "{$gen->key()} => {$gen->current()}";The above example will output:
output
key => value