note 102348 deleted from class.arrayobject by danbrown

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
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);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.