I have the 'Article' class with the private property words
which holds and array of Word
class objects. I also have getWord
method which can return one word:
class Article {
private $words = Array(1 => new Word(1), 2 => new Word(2), ...);
public function getWord($wordId) {
if (array_key_exists($wordId, $this->words)) {
return $this->words[$wordId];
} else {
return NULL;
}
}
}
I need to iterate through all exising words. What is the best way to do that?
Currently I'm returning all words as array using another method, but I don't think that is a good option.