note 86822 added to class.filteriterator
| From: | VenelinVulkov at osu1 dot php dot net | Date: | Wed, 05 Nov 2008 08:36:49 +0000 |
| Subject: | note 86822 added to class.filteriterator | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-146153@lists.php.net to get a copy of this message | ||
The code below is a simple example of usage . Note that the method which does the actual job is
accept.
<?php
class UserFilter extends FilterIterator
{
private $userFilter;
public function __construct(Iterator $iterator , $filter )
{
parent::__construct($iterator);
$this->userFilter = $filter;
}
public function accept()
{
$user = $this->getInnerIterator()->current();
if( strcasecmp($user['name'],$this->userFilter) == 0) {
return false;
}
return true;
}
}
$array = array(
array('name' => 'Jonathan','id' => '5'),
array('name' => 'Abdul' ,'id' => '22')
);
$object = new ArrayObject($array);
// Note it is case insensitive check in our example due the usage of strcasecmp function
$iterator = new UserFilter($object->getIterator(),'abdul');
foreach ($iterator as $result) {
echo $result['name'];
}
/* Outputs Jonathan */
?>
Regards.
----
Server IP: 128.39.198.38
Probable Submitter: 193.142.0.1
----
Manual Page -- http://www.php.net/manual/en/class.filteriterator.php
Edit -- https://master.php.net/note/edit/86822
Del: integrated -- https://master.php.net/note/delete/86822/integrated
Del: useless -- https://master.php.net/note/delete/86822/useless
Del: bad code -- https://master.php.net/note/delete/86822/bad+code
Del: spam -- https://master.php.net/note/delete/86822/spam
Del: non-english -- https://master.php.net/note/delete/86822/non-english
Del: in docs -- https://master.php.net/note/delete/86822/in+docs
Del: other reasons-- https://master.php.net/note/delete/86822
Reject -- https://master.php.net/note/reject/86822
Search -- https://master.php.net/manage/user-notes.php