note 102348 deleted from class.arrayobject by danbrown
| From: | danbrown@php.net | Date: | Wed, 09 Feb 2011 23:21:14 +0000 |
| Subject: | note 102348 deleted from class.arrayobject by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-176831@lists.php.net to get a copy of this message | ||
Note Submitter: nuno.vieira at ua.pt
----
The note above posted by tony at tonyandcarol dot com could be improved adding the methods:
function getCollection()
{
return $this->data;
}
function exists($_id)
{
if($_thisObject = $this->data->offSetExists($_id))
return true;
else
return false;
}
The first one might be useful to call an iterator:
$iterator = $myCollection->getCollection()->getIterator();
while($iterator->valid())
{
echo $iterator->key() . ' => ' . $iterator->current()->getObject() .
"\n";
$iterator->next();
}
The second one might be useful to control the function addObject($_id, $_object).
if($myCollection->exists($key))
$myCollection->addObject($key,$myCollection->getObject($key)+1);
else
$myCollection->addObject($key, 1);