I have an entry that could have several comments associated with that entry.
If I were doing this in C# I would build a collection of these comments. However, I’m unfamiliar with a way to do this in PHP.
My current thought process is to have a comment object that has a method that would build and data_array based off of IDs and then just call that object and utilize the data that way.
Is that the easiest most basic way of doing that? Or is there a better (right way) of building a collection for PHP?
My pseudo code:
class entry
var $id
var $text
class comments
var $id
var $entryId
var $text
var $data_array;
function getCollectionById(){
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$da[$i] = array('entryId'=>$row["entryId"],'text'=>$text);
}
$this->data_array = $da;
}
The arrays can simulate collections very effectively:
you can loop through it with foreach