PHP | Ds\Sequence filter() Function Last Updated : 11 Jul, 2025 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: https://www.php.net/manual/en/ds-sequence.filter.php Comment More info V vijay_raj Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-DS\Collection Explore PHP Tutorial 8 min read BasicsPHP Syntax 4 min read PHP Variables 5 min read PHP | Functions 8 min read PHP Loops 4 min read ArrayPHP Arrays 5 min read PHP Associative Arrays 4 min read Multidimensional arrays in PHP 5 min read Sorting Arrays in PHP 4 min read OOPs & InterfacesPHP Classes 2 min read PHP | Constructors and Destructors 5 min read PHP Access Modifiers 4 min read Multiple Inheritance in PHP 4 min read MySQL DatabasePHP | MySQL Database Introduction 4 min read PHP Database connection 2 min read PHP | MySQL ( Creating Database ) 3 min read PHP | MySQL ( Creating Table ) 3 min read PHP AdvancePHP Superglobals 6 min read PHP | Regular Expressions 12 min read PHP Form Handling 4 min read PHP File Handling 4 min read PHP | Uploading File 3 min read PHP Cookies 9 min read PHP | Sessions 7 min read Like