PHP Doku:: The RecursiveFilterIterator class - class.recursivefilteriterator.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzSonstige GrunderweiterungenStandard PHP Library (SPL)IteratorenThe RecursiveFilterIterator class

Ein Service von Reinhard Neidl - Webprogrammierung.

Iteratoren

<<RecursiveDirectoryIterator::rewind

RecursiveFilterIterator::__construct>>


UnterSeiten:

The RecursiveFilterIterator class

Einführung

This abstract iterator filters out unwanted values for a RecursiveIterator. This class should be extended to implement custom filters. The RecursiveFilterIterator::accept() must be implemented in the subclass.

Klassenbeschreibung

RecursiveFilterIterator extends FilterIterator implements Iterator , Traversable , OuterIterator , RecursiveIterator {
/* Methoden */
public void getChildren ( void )
public void hasChildren ( void )
/* Geerbte Methoden */
abstract bool FilterIterator::accept ( void )
mixed FilterIterator::current ( void )
mixed FilterIterator::key ( void )
void FilterIterator::next ( void )
void FilterIterator::rewind ( void )
bool FilterIterator::valid ( void )
}

Inhaltsverzeichnis


Ein BenutzerBeitrag:
- Beiträge aktualisieren...
Russell Dias
28.09.2010 15:38
I had to create a filter to get values greater than a certain number in a multidimensional array.

Hope someone else finds it helpful:

<?php
class GreaterThanFilter extends RecursiveFilterIterator {
    protected
$limit;

    public function
__construct(RecursiveIterator $recursiveIter, $limit) {
       
$this->limit = $limit;
       
parent::__construct($recursiveIter);
    }
    public function
accept() {
        return
$this->hasChildren() || strlen($this->current()) >= $this->limit;
    }
     public function
getChildren() {
        return new
self($this->getInnerIterator()->getChildren(), $this->limit);
    }
}
$iter = new RecursiveArrayIterator($array);
$filter   = new GreaterThanFilter($iter, 5);

foreach(new
RecursiveIteratorIterator($filter) as $key => $value)
{
    echo
$value . "\n";
}
?>



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)