ColumnIterator in reverse order #4100
Closed
wolverine4277
started this conversation in
General
Replies: 1 comment
-
Can you make use of the following answer from @mpen in https://stackoverflow.com/questions/5315539/iterate-in-reverse-through-an-array-with-php-spl-solution: /**
* Iterate an array or other foreach-able without making a copy of it.
*
* @param array|\Traversable $iterable
* @return Generator
*/
function iter_reverse($iterable) {
for (end($iterable); ($key=key($iterable))!==null; prev($iterable)){
yield $key => current($iterable);
}
}
//Usage:
foreach(iter_reverse($my_array) as $key => $value) {
// ... do things ...
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I'm trying to use iterators to go through columns or rows in reverse order but I can't find a way to do it.
So far I have tried the following (I'm using a simple xls with columns from A to N):
The above code only print the last column N.
If i use something like this:
The above code prints correctly NMLKJIHGFEDCBA but if I use a xls with many columns the code throws my this error:
in line:
new \ArrayIterator(range($highestColumn, 'A'));
Evidently something I'm not taking into account but I can't figure it out.
I would appreciate any help.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions