PHP | Ds\Deque filter() Function Last Updated : 14 Aug, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 the callback function which contains the definition of filter to the elements from the deque. Return Value: This function returns a new Deque which contains all the values for which callback returns True or all values that convert to True if a callback was not provided. Below programs illustrate the Ds\Deque::filter() function in PHP: Program 1: PHP <?php // Creating a deque $deque = new \Ds\Deque([1, 2, 3, 4, 5, 6]); echo("Elements in the deque are\n"); print_r($deque); // Use filter() function to filter // the elements as per requirement print_r($deque->filter(function($value) { return $value % 2 == 0; })); ?> Output: Elements in the deque are Ds\Deque Object ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 ) Ds\Deque Object ( [0] => 2 [1] => 4 [2] => 6 ) Program 2: PHP <?php // Creating a deque $deque = new \Ds\Deque([10, 20, 3, 40, 50, 6]); echo("Elements in the deque are\n"); print_r($deque); // Use filter() function to filter // the elements as per requirement print_r($deque->filter(function($value) { return $value % 10 != 0; })); ?> Output: Elements in the deque are Ds\Deque Object ( [0] => 10 [1] => 20 [2] => 3 [3] => 40 [4] => 50 [5] => 6 ) Ds\Deque Object ( [0] => 3 [1] => 6 ) Reference: http://php.net/manual/en/ds-deque.filter.php Comment More infoAdvertise with us Next Article PHP | DsSequence filter() Function B barykrg Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_map Similar Reads 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 | 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 | 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 first() Function The Ds\Deque::first() function is an inbuilt function in PHP which returns the first value in the Deque if Deque is not empty. Syntax: public Ds\Deque::first( void ) : mixed Parameters: This function does not accept any parameter. Return Value: This function returns the first element from the Deque, 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 | Ds\Deque filter() Function min read Like