1--TEST-- 2Generators can also yield keys 3--FILE-- 4<?php 5 6function reverse(array $array) { 7 end($array); 8 while (null !== $key = key($array)) { 9 yield $key => current($array); 10 prev($array); 11 } 12} 13 14$array = [ 15 'foo' => 'bar', 16 'bar' => 'foo', 17]; 18 19foreach (reverse($array) as $key => $value) { 20 echo $key, ' => ', $value, "\n"; 21} 22 23?> 24--EXPECT-- 25bar => foo 26foo => bar 27