I don’t know if a array is really a object on php … but, what I want is to change the array behavior on a foreach loop.
Something similar to this on java:
for( String it : myArr = new Array_Iterator( array) implements Iterator{
public Array_Iterator( String[] arr){ this.arr = arr}
/* interface implementation */
}){
/* loop */
}
What I really want to accomplish is a kind of filter, so that I don’t get entries from the array that I don’t want
Just wrap the Array into an ArrayIterator and you’re free to overwrite the regular methods. The Spl provides a number of other Iterators and Interfaces you might find useful. To filter arrays through iterators, use could use the FilterIterator.
Example from PHP Manual: