Questions tagged [arrayiterator]

An iterator specifically for traversal through arrays. Appears in PHP and the Java Apache API among others.

An specifically for traversal through .

Appears in PHP and the Java Apache API among others.

37 questions
35
votes
7 answers

Difference between ArrayIterator, ArrayObject and Array in PHP

Can somebody explain clearly the fundamental differences between ArrayIterator, ArrayObject and Array in PHP in terms of functionality and operation? Thanks!
jkhamler
  • 543
  • 2
  • 6
  • 13
16
votes
7 answers

How do I alter array keys and values while using a RecursiveArrayIterator?

I suspect I'm doing something stupid here, but I'm confused by what seems like a simple problem with SPL: How do I modified the contents of an array (the values in this example), using a RecursiveArrayIterator / RecursiveIteratorIterator? Using the…
John Carter
  • 53,924
  • 26
  • 111
  • 144
8
votes
2 answers

How can I check if an array contains a specific key in php

I know how to check for a value in an array, but how do I check for a value in an Array Iterator? $array = new ArrayIterator(array( '1QmRjtsw2UQ' => array('pubdate' => '26 Jun 15', 'alt' => '8 Year Old Beautifully Covers Thinking Out Loud', 'anchor…
Mike
  • 607
  • 8
  • 30
8
votes
2 answers

How can I make ArrayIterator or ArrayObject work with implode?

I'm having a few problems with ArrayIterator (And, indeed, the same problem with ArrayObject). For 99% of everything, my extended ArrayIterator behaves like an array and is working great. Unfortunately, implode() does not like being given an…
Oli Comber
  • 311
  • 2
  • 11
7
votes
1 answer

What does “Using non reentrant iterator method: Array.iterator()” error message mean?

This is my first project in libGDX and I am trying to loop a com.badlogic.gdx.utils.Array: //properties ... private Array items; ... //constructor ... items = new Array(); ... //render method ... for (Item item : items) { …
Waqleh
  • 9,741
  • 8
  • 65
  • 103
7
votes
2 answers

PHP ArrayObject / ArrayIterator : concept with example

I'm trying to understand the concept of the Object Array in PHP. Up to date I was simply using regular arrays to loop through the list of records and display them in say table. I know that I could do this using Object, but I'm not quite sure how to…
Spencer Mark
  • 5,263
  • 9
  • 29
  • 58
5
votes
0 answers

PHP ArrayIterator and current()

I have this piece of PHP code: echo 'PHP ' . phpversion()."\n"; $arr = array(); for ($i=0; $i<10; $i++) { $arr[] = new stdClass(); } $it = new ArrayIterator($arr); $i = 1; foreach ($it as $obj) { $obj->test = $i; …
andreas
  • 149
  • 3
  • 12
4
votes
2 answers

How do i clone an ArrayIterator in PHP?

I am trying to clone an \ArrayIterator object, but it seems like the cloned one is still referencing to the original one. $list = new \ArrayIterator; $list->append('a'); $list->append('b'); $list2 = clone…
Eimihar
  • 135
  • 2
  • 7
3
votes
1 answer

How do I append an element with a key using ArrayIterator in PHP?

There is no documentation on the PHP site for the ArrayIterator object beyond a basic parameter reference, so I'm not even sure this is possible. I understand the concept of the ArrayIterator in a basic sense like this example: $rows = new…
oucil
  • 4,211
  • 2
  • 37
  • 53
3
votes
4 answers

Why iterating over ArrayIterator ending with endless loop?

Array in my code is quite big so I pasting it in pastebin. http://pastebin.com/6tviT2Xj I don't understand why I am getting endless loop Logic of this script is: $it = new ArrayIterator($options); while($it->valid()) { print $it->key(); …
Codium
  • 3,200
  • 6
  • 34
  • 60
3
votes
1 answer

Why implement two interfaces that already extend each other?

I am trying to understand something about ArrayObject and ArrayIterator classes ArrayObject: This class implements the IteratorAggregate and Traversable interfaces. Since IteratorAggregate extends Traversable itself, why does ArrayObject implement…
Aviel Fedida
  • 4,004
  • 9
  • 54
  • 88
2
votes
2 answers

Can't we iterate material-ui inside an array in React.js?

I have been trying to use material-ui and iterate over it inside an array ( for creating ratings for some items like in e-commerce sites). The code isn't working. On my localhost server, it's not showing any stars at all. Before I made it dynamic,…
2
votes
5 answers

Are Iterators faster than array[i]?

Possible Duplicate: Why use iterators instead of array indices? Because for the life of me I can't figure out how they're not redundant. vector::iterator iter1 vector::const_iterator iter2 Maybe they're faster?
navand
  • 1,379
  • 1
  • 16
  • 20
2
votes
1 answer

ORM Query results: Arrays vs Result handle wrapped in Iterator interface

Okay, here's one for the pro's: For a couple of years now, i've been working on my own PHP ORM/ActiveRecord implementation that i named Pork.dbObject. It's loosly based on the 'make your own site with rails in 5 minutes' movie we all saw a couple of…
SchizoDuckie
  • 9,353
  • 6
  • 33
  • 40
2
votes
2 answers

How to optimize an ArrayIterator implementation in PHP?

I have a long running PHP daemon with a collection class that extends ArrayIterator. This holds a set of custom Column objects, typically less than 1000. Running it through the xdebug profiler I found my find method consuming about 35% of the…
Matt S
  • 14,976
  • 6
  • 57
  • 76
1
2 3