I am wondering how I can create a list of one of my classes. As an example, I have a class called Product, and it has properties of ProductID, and ProductName. These values get pulled and populated from the database via accessors.
How can I create an object, say, $objProducts that contains a list of class Product. Then, I could loop through $objProducts looking at each individual Product object.
In VB.NET you can do this by: Dim objProducts As New List Of clsProduct. Then I can add instances of clsProduct to this list.
Can I use an ArrayList? Is there something better I can use? I just started using PHP today, but I wasn't able to find anything about this.
Thanks!
How To Create List of Class?
Moderator: General Moderators
Re: How To Create List of Class?
You just make an array. PHP doesn't care about what you put in it.
Code: Select all
$array = array();
$array[] = new Product();
$array[] = new Product();
$array[] = 123; // oops, a number. not a problem though
$array[] = new Product();Re: How To Create List of Class?
Thanks. 