PHP | Ds\Sequence filter() Function Last Updated : 21 Aug, 2019 Comments Improve Suggest changes Like Article Like Report 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 <?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 <?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 Comment More infoAdvertise with us Next Article PHP | DsVector slice() Function V vijay_raj Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-DS\Collection Similar Reads PHP | DsMap filter() Function The Ds\Map::filter() function is an inbuilt function in PHP which is used to create a new map using the filter function. Syntax: public Ds\Map::filter( $callback ) Parameters: It contains a single parameter $callback which is an optional parameter and it returns True if the value should be included, 2 min read PHP | DsSet filter() Function The Ds\Set::filter() function is an inbuilt function in PHP which is used to create new set using filter function. Syntax: Ds\Set public Ds\Set::filter( $callback ) Parameters: This function accepts single parameter $callback which is optional and it returns True if the value should be included, Fal 1 min read PHP | DsDeque filter() Function The Ds\Deque::filter() function is an inbuilt function in PHP which is used to filter out the elements from the deque based on the operation defined in the callback function. Syntax: public Ds\Deque::filter( $callback ) : Ds\Deque Parameters: This function accepts single parameter $callback which is 2 min read PHP | preg_filter() Function The preg_filter() function is an inbuilt function in PHP which is used to perform a regular expression search and replace the text. Syntax: preg_filter( $pattern, $replacement, $subject, $limit, $count ) Parameters: This function accepts five parameters as mention above and describe below. $pattern: 2 min read PHP | DsVector filter() Function The Ds\Vector::filter() function is used to filter out the only elements which satisfy the condition defined in the callback function. After doing a filter on the vector, it will eliminate the elements which do not satisfy the condition mentioned in the function. Syntax: Ds\Vector public Ds\Vector:: 2 min read PHP | DsVector reduce() Function The Ds\Vector::reduce() function is an inbuilt function in PHP which reduce the vector to a single value by applying operations in the callback function. Syntax: mixed public Ds\Vector::reduce( $callback, $initial ) Parameters: This function accepts two parameters as mentioned above and described be 2 min read PHP | DsSet slice() Function The Ds\Set::slice() function is an inbuilt function in PHP which is used to return the sub-set of given range. Syntax: Ds\Set public Ds\Set::slice ( int $index [, int $length ] ) Parameters: This function accepts two parameters as mentioned above and described below: $index: This parameter holds the 2 min read PHP | DsSequence filter() Function 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, F 1 min read PHP | DsVector slice() Function The Ds\Vector::slice() function is an inbuilt function in PHP which is used to return the sub-vector of the given vector. Syntax: Ds\Vector public Ds\Vector::slice( $index, $length )/pre> Parameters: This function accepts two parameter as mentioned above and described below: $index: This parameter h 2 min read PHP | DsVector set() Function The Ds\Vector::set() function is an inbuilt function in PHP which is used to set the value in the vector at the given index. Syntax: void public Ds\Vector::set( $index, $value ) Parameters: This function accepts two parameters as mentioned above and described below: $index: This parameter holds the 2 min read Like