Ds\Sequence::filter() 函數可以使用 callable 創建一個新序列來確定要包含哪些值。
用法
public abstract Ds\Sequence Ds\Sequence::filter([ callable $callback ] )
Ds\Sequence::filter() 函數可以返回一個新序列,該序列包含回調返回 true 的所有值,或者如果未提供回調則轉換為 true 的所有值。
例子1
<?php
$seq = new \Ds\Vector([10, 20, 30, 40, 50]);
var_dump($seq->filter(function($val) {
return $val % 4 == 0;
}));
?>
例子2
<?php
$seq = new \Ds\Vector([2, 3, 5, 7, 9, 10]);
var_dump($seq->filter(function($val) {
return $val;
}));
?>
相關用法
- PHP Ds Sequence capacity()用法及代碼示例
- PHP Ds Sequence sort()用法及代碼示例
- PHP Ds Sequence insert()用法及代碼示例
- PHP Ds Sequence slice()用法及代碼示例
- PHP Ds Sequence reduce()用法及代碼示例
- PHP Ds Sequence sorted()用法及代碼示例
- PHP Ds Sequence shift()用法及代碼示例
- PHP Ds Sequence get()用法及代碼示例
- PHP Ds Sequence join()用法及代碼示例
- PHP Ds Sequence rotate()用法及代碼示例
- PHP Ds Sequence pop()用法及代碼示例
- PHP Ds Sequence remove()用法及代碼示例
- PHP Ds Sequence contains()用法及代碼示例
- PHP Ds Sequence allocate()用法及代碼示例
注:本文由純淨天空篩選整理自 PHP - Ds Sequence filter() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。