"stuart" <st******@webobjectives.com.au> schreef in bericht
news:st****************************@news-vip.optusnet.com.au...
Hi there,
I have an array of objects, and I would like to retreive one of the
objects based on a given key and value (ie. name='john'). Is this
possible and if so what is the syntax?
thanks
Stuart
Strange how different people seem to understand your question differently
(this is a hint!). This is what I think you absolutely propably need :)
for ($i = 0; $i < count($array); $i++) {
$object = $array[$i];
if ($object->name == 'john') break;
$object = NULL;
}
After this for loop $object contains the first object in the array with the
name 'john', or it is NULL if no object had that name. You can test that
very easily with the function is_null():
if (is_null($object)) {
echo 'I could not find an object with that name!';
}
Hope this helps.
Remon.