PHP | Ds\Set filter() Function Last Updated : 22 Aug, 2019 Comments Improve Suggest changes Like Article Like Report 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, False otherwise. Return value: This function returns a new set 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\Set::filter() function in PHP: Program 1: php <?php // Create new set $set = new \Ds\Set([10, 20, 30, 40, 50]); // Display new set using filter function var_dump($set->filter(function($val) { return $val % 4 == 0; })); ?> Output: object(Ds\Set)#3 (2) { [0]=> int(20) [1]=> int(40) } Program 2: php <?php // Create new set $set = new \Ds\Set([2, 5, 4, 8, 3, 9]); // Display new set using filter function var_dump($set->filter(function($val) { return $val; })); ?> Output: object(Ds\Set)#3 (6) { [0]=> int(2) [1]=> int(5) [2]=> int(4) [3]=> int(8) [4]=> int(3) [5]=> int(9) } Reference: https://www.php.net/manual/en/ds-set.filter.php Comment More infoAdvertise with us Next Article PHP | DsMap filter() Function R R_Raj Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_set Similar Reads 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 | 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 | 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 | 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 | 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 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 | DsDeque set() Function The Ds\Deque::set() function is an inbuilt function in PHP which is used to set the value at the given index in the Deque. Syntax: public Ds\Deque::set( $index, $value ) : void Parameters: This function accept two parameters as mentioned above and described below: index: This parameter holds the ind 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 | filter_id() Function The filter_id() function is an inbuilt function in PHP which returns the filter ID of a specified filter name. It is used to get the filter id of the particular filter in PHP by using filter_id function by giving the name of the filter as input and get the associated id to it. Syntax: int filter_id( 2 min read PHP DsSet sort() Function The Ds\Set::sort() function of DS\Set class in PHP is used to in-place sort the elements of a specified Set instance according to the values. By default, the Set is sorted according to the increasing order of the values. Syntax: void public Ds\Set::sort ([ callable $comparator ] ) Parameters: This f 2 min read Like