<?php
class class1{
var $objects = array();
function class1(){
// empty construct
}
function addobject($pID){
$object = new class2($pID);
$this->objects[] = $object;
}
}
class class2{
var $id;
function class2($pID){
$this->id = $pID;
}
function doSomething(){
// this function does something useful
}
}
// END CLASSES
$myclass = new class1();
$myclass->addobject("object1");
?>
oo thanks.
OK, in the real-world example I'm working with. I wont know what the object number is in the array but all the objects have an "id" property. How would i go about finding the right object?
the id property is a name, in the form of a string.
I updated my example to show this. Thanks again.
... do i simply need to just loop through until i find the right one?
ie.
foreach ($myclass->objects as $object){
if ($object->id == $idIWant){
$object->doSomething();
}
}
It didnt seem to work, but is it something like that? feels like a bit of a messy solution.