I think this is obvious in case of this simple xml because the simple xml functions returns the object array rather than the normal associative or numeric array. So why not just increment a variable and show with that?
AFAIK, this means the first SimpleXML object stored as a first element in the array. So every element in the DOM is represented as a object and if there are multiple elements then they will be in an array of collection of their own as objects.
But I can access any of those particular objects individually by the numeric array key shown.
For example:
$xml->gallery[0]->item[1];
I get that particular object stored in [item][1].
So they are in fact objects stored into an associative array, accessible by the numeric associative keys.
Since the individual objects, stored into the [item] array, are individually accessible by the numeric associative keys, then there must be a way to access those keys?
Then the ‘item’ is not an associative array and hence this is an object. I don’t have quite deep knowledge on this though so i will let others to put their thought here about this. But for now if you really dont wanna waste much time and go ahead with works just do what you have done with counter variable. If you are here to gain the knowledge then lets wait other’s ideas too if anyone does have good solution and/or the fact how the SimpleXML returns the array.
I see what you are saying. I have added the counter to keep moving forward with my project. But would like to understand these simplexml objects better.
I don’t think they actually implement ArrayAccess, but the point is that it’s possible to use array like bracket syntax on objects. Since they define their own iterator behavior, the object is in charge of what it should produce as the “key” when it’s being iterated. It doesn’t look like it will ever produce a numeric key. So print_r() is probably just generating it’s own.