(PHP 5 >= 5.5.0, PHP 7, PHP 8)
Generator::key — 返回當前產生的鍵
獲取產生的值的鍵
此函數沒有參數。
返回當前產生的鍵。
示例 #1 Generator::key() example
<?phpfunction Gen(){ yield 'key' => 'value';}$gen = Gen();echo "{$gen->key()} => {$gen->current()}";
以上例程會輸出:
key => value