PHP | Ds\Deque map()函数
Ds\Deque::map()函数是PHP中的一个内置函数,用于返回根据回调函数执行的操作修改每个元素的 Deque。
句法:
public Ds\Deque::map( $callback ) : Ds\Deque
参数:此函数接受单个参数$callback ,其中包含要对 Deque 的每个元素执行的操作的可调用函数。
返回值:此函数返回一个修改了每个元素的 Deque。
下面的程序说明了PHP中的Ds\Deque::map()函数:
方案一:
map(function($element) {
// performing operation on each element
return $element * 10;
}));
?>
输出:
Elements of deque
Ds\Deque Object
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
)
Ds\Deque Object
(
[0] => 10
[1] => 20
[2] => 30
[3] => 40
[4] => 50
[5] => 60
)
方案二:
map(function($element) {
// performing operation on each element
return $element / 10;
}));
?>
输出:
Elements of deque
Ds\Deque Object
(
[0] => 10
[1] => 20
[2] => 30
[3] => 40
[4] => 50
[5] => 60
)
Ds\Deque Object
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
)
参考: http: PHP。 PHP