Entry
Can I store an array of objects as an object variable?
Jul 13th, 2000 12:21
Ben Udall, Kyle Olsen,
Yes, it is possible to store an array of objects as an object variable.
However, there are some syntax quirks to take note of.
class client
{
var $first_name;
var $last_name;
var $id;
}
class dept_info
{
var $name;
var $clients;
}
$cs_dept = new dept_info;
// Create a temporary client object
$cs_client = new client;
$cs_client->first_name = 'John';
$cs_client->last_name = 'Doe';
$cs_client->id = 12345;
// Set the array element to the temporary object
$cs_dept->clients[0] = $cs_client;