0

I was thinking about AccessArray interface and the Iterator interface and i was thinking can we combine them?, I mean Setting up array with AccessArray and use a foreach loop with the Iterator, If can some one please help me with example if it possible to combine those two.

2 Answers 2

2

Note that you are basically asking for ArrayObject.

class Foo extends ArrayObject
{
  private $data = [];
  public function __construct()
  {
    parent::__construct($this->data);
  }
}
Sign up to request clarification or add additional context in comments.

3 Comments

ArrayObject additional Serializable, Countable and instead of Iterator IteratorAggregate and Traversable. The OP maybe doesn't want this, but must say: Don't think so either.
Yeah, it's definitely more than what he explicitly asked for, but I often see people ultimately reimplementing ArrayObject because they don't know it exists.
Thank you Matthew, becouse of you i understand the concept if built-in behavior, thank you again and have a nice day.
2
class Foo implements ArrayAccess, Iterator {
  // Implement interfaces here
}

You can implement as many interfaces as you like.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.