Syntax:DsSet public DsSet::filter ($callback)
Parameters: This function takes one parameter
$callback,which is optional, and returns True if the value should be included, otherwise False.
Returned value: this function returns a new set containing all values for which the callback returned True, or all values that convert to True if no callback was provided.The programs below illustrate the Ds / Set function::filter()in PHP:Program 1: php
// Create a new set
$set
=
new
DsSet ([10, 20, 30, 40, 50]);
// Display the new set using the filter function
var_dump (
$set
-> filter ( function
(
$val
) {
return
$val
% 4 == 0;
}));
?>
Exit:object (DsSet ) # 3 (2) {[0] = > int (20) [1] = > int (40)}
Program 2: Php
// Create a new set
$set
=
new
DsSet ([2, 5 , 4, 8, 3, 9]);
// Display the new set using the filter function
var_dump (
$set
-> filter ( function
(
$val
) {
return
$val
;
}));
?>
Exit:object (DsSet ) # 3 (6) {[0] = > int (2) [1] = > int (5) [2] = > int (4) [3] = > int (8) [4] = > int (3) [5] = > int (9)}
Link: https: / /www.php.net/manual/en/ds-set.filter.php