There is a function that returns a dictionary generator. For example, this:
function foo() { for ($i = 0; $i < 10; $i++) yield "key-$i" => $i * 3; } It’s just that you don’t access the array as a key: $item = foo()['key-1'];
You can of course convert it to an array using iterator_to_array , but this is not very economical. I want something like:
function get_iterator_item($it, $key) { foreach ($it as $k => $v) { if ($k === $key) return $v; } return false; } Is there something so standard?
iterator_to_arrayfunction is much faster and more productive. - Anditerator_to_array: 1.001358get_iterator_item: 4.053115 - Anditerator_to_array: 0.160762get_iterator_item: 0.186655 - And