PHP code example of delboy1978uk / collection-filter
1. Go to this page and download the library: Download delboy1978uk/collection-filter library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// firstly, use these
use ArrayIterator;
use Del\Filter\Filter\FilterInterface;
// next, make your class implement FilterInterface
class NumberSixFilter implements FilterInterface
{
/**
* Then create this method
*
* @param ArrayIterator $collection
* @return ArrayIterator
*/
public function filter(ArrayIterator $collection) : ArrayIterator
{
// We need to pass back results
$results = new ArrayIterator();
// loop through the collection passed in
while ($collection->valid()) {
// Get the current row
$current = $collection->current();
// This is my actual example filter.
// If the current row is an integer that ISN'T 6, add it!
// And if it isn't an integer add it regardless
if (is_integer($current) && $current != 6) {
$results->append($current);
} elseif (!is_integer($current)) {
$results->append($current);
}
// Move on to the next item
$collection->next();
}
// Finally, return the results
return $results;
}
}
use Del\Filter\CollectionFilter;
use Your\CustomFilter;
$filter = new CollectionFilter();
$customFilter = new CustomFilter();
$filter->getFilterCollection()->append($customFilter);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.