The Ds\Sequence::filter() function is an inbuilt function in PHP which is used to create new sequence using filter function.
Syntax:
Ds\Sequence abstract public Ds\Sequence::filter ([ callable $callback ] )
Parameter: It is an optional parameter and it returns True if the value should be included, False otherwise.
Return value: This function returns a new sequence containing all the values for which either the callback returned True or all values that convert to True if a callback was not provided.
Below programs illustrate the Ds\Sequence::filter() function in PHP:
Example 1:
<?php   // Create new sequence $seq = new \Ds\Vector([10, 20, 30, 40, 50]);   // Display new sequence using filter function var_dump($seq->filter(function($val) {     return $val % 4 == 0; }));   ?> |
Output:
object(Ds\Vector)#3 (2) {
[0] => int(20)
[1] => int(40)
}
Example 2:
<?php   // Create new sequence $seq = new \Ds\Vector([2, 5, 4, 8, 3, 9]);   // Display new sequence using filter function var_dump($seq->filter(function($val) {     return $val; }));   ?> |
Output:
object(Ds\Vector)#3 (6) {
[0] => int(2)
[1] => int(5)
[2] => int(4)
[3] => int(8)
[4] => int(3)
[5] => int(9)
}
Reference: http://php.net/manual/en/ds-sequence.filter.php

… [Trackback]
[…] Find More on on that Topic: geeksforgeeks.org/php-ds-sequence-filter-function-2/ […]
… [Trackback]
[…] Here you can find 104 more Information to that Topic: geeksforgeeks.org/php-ds-sequence-filter-function-2/ […]