php - Enumerate Iterator to array -
So I have these generators
objects - you know who make lazy calculations easy. Sometimes, though, I do not want lazy calculations: I want to take that data which I usually repeat and put it in the array - but for PHP.
Most of the time I want a generator, but I have some time now where I need an array, for example, if there is a possibility of enumerating the data several times, and all the items being repeated There is less chance of preventing the counting process before.
Is there some internal PHP function that outputs iterator
or traversal
and an array? I do not really want to write my own function / method Yes, I know, this will be a small, simple process, but I would like to avoid having a screwed work about it.
Just to avoid "indefensible use of an advanced loop" inevitable, here's the approach:
& lt ;? Php Function Enumerate (\ TRUSTABLE $ ETHERTER) {$ array = []; Forex Currency ($ $ $ as $ $ => $ v) {$ array [$ k] = $ v; } $ Array returned; }
I have some other hacks ideas, but what I actually see is a function that does not require any additional code, files or libraries. Nothing fancy
Use
iterator_to_array
Description
array iterator_to_array (> 5 PHP = 5.1.0)
iterator_to_array - Copy the Iterator to an array
Description
Traversable $ Eater [, using Bull $ _Keys = true])
Comments
Post a Comment