Function returns an array of objects...
| From: | Amit Snyderman | Date: | Fri, 28 Feb 2003 06:24:54 +0000 |
| Subject: | Function returns an array of objects... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-137519@lists.php.net to get a copy of this message | ||
so i have a function that creates objects (with member variables) and pushes those objects onto the array. after adding all of the objects, the function then returns the array...
i'm having trouble accessing the members of each object in the array...i'm trying to do something like this:
class Object {
var $id;
function Object($param) {
$this->id = $param;
}
}
function getArrayOfObjects() {
$theArray = array();
for ($i = 0; $i < 10; $i++) {
$theArray[] = new Objects($i);
}
return $theArray;
}
$temp = getArrayOfObjects();
echo $temp[0]->id; // this should display "0"
do i have to do something with references or dereference the id variable some other way? i'm coming from java where something like this is extremely easy...
thanks
amit