Arrays in Classes
| From: | Richard S. Crawford | Date: | Sun, 18 Mar 2001 23:44:14 +0000 |
| Subject: | Arrays in Classes | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-44465@lists.php.net to get a copy of this message | ||
I'm quite new at object-oriented programming in PHP. Here's what I want to do.
I want to create a class of objects called "lists". The properties I want to have for list objects include:
owner of the list
number of items in the list
the list itself
Each item in the list, of course, has several properties of their own: the date the item was added, the name of the item, and a link to the item. I figured that the list would be contained in an array of associative arrays... such as,
item[0]["item"]="Palm Pilot"
item[0]["dateAdded"]="2001-03-18"
item[0]["link"]="http://www.palm.com"
The lists will be built from a database which contains information about users and the lists that they maintain. The database part I have down pat.
Properties of the list objects can be retrieved like this, of course...
$myList=new List($userID);
$num=$myList->numItems;
$name=$myList->listOwner;
What I'm wondering is, can I do something like this:
for($i=0;$i<$num;$i++)
$itemList[$i]["item"]=$myList->item[$i]["item"];
If so, how???