Ds \ Deque :: apply()function是PHP中的内置函数, 用于通过执行回调函数定义的操作来更新Deque的值。
语法如下:
public Ds\Deque::apply( $callback ) : void
参数:该函数接受单个参数$ callback包含该函数的函数定义了要对双端队列的每个元素执行的操作。
返回值:此函数不返回任何值。
下面的程序说明了Ds \ Deque :: apply()PHP中的功能:
程序1:
<
?php// Declare deque
$deck = new \Ds\Deque([1, 2, 3, 4, 5, 6]);
echo ( "\nElements in the deque are\n" );
// Display the deque elements
print_r( $deck );
// Use apply() function to implement
// the operation
$deck ->
apply( function ( $element ) {
return $element * 10;
});
echo ( "\nUpdated elements in the deque\n" );
// Display the deque elements
print_r( $deck );
?>
输出如下:
Elements in the deque are
Ds\Deque Object
(
[0] =>
1
[1] =>
2
[2] =>
3
[3] =>
4
[4] =>
5
[5] =>
6
)Updated elements in the deque
Ds\Deque Object
(
[0] =>
10
[1] =>
20
[2] =>
30
[3] =>
40
[4] =>
50
[5] =>
60
)
程式2:
<
?php// Declare deque
$deck = new \Ds\Deque([10, 20, 30, 40, 50, 60]);
echo ( "\nElements in the deque are\n" );
// Display the deque elements
print_r( $deck );
// Use apply() function to implement
// the operation
$deck ->
apply( function ( $element ) {
return $element % 10;
});
echo ( "\nUpdated elements in the deque\n" );
// Display the deque elements
print_r( $deck );
?>
输出如下:
Elements in the deque are
Ds\Deque Object
(
[0] =>
10
[1] =>
20
[2] =>
30
[3] =>
40
[4] =>
50
[5] =>
60
)Updated elements in the deque
Ds\Deque Object
(
[0] =>
0
[1] =>
0
[2] =>
0
[3] =>
0
[4] =>
0
[5] =>
0
)
【PHP Ds Deque apply()函数用法介绍】参考: http://php.net/manual/en/ds-deque.apply.php
推荐阅读
- AngularJS 事件介绍和用法详细介绍
- 如何使用JavaScript切换布尔值()
- 使用Java中的正则表达式获取字符串中每个单词的首字母
- 算法(一个检查字符串是否相互旋转的程序)
- 如何使用Python和其他语言为变量赋值
- JavaScript 严格模式解析和使用示例
- 5步骤简单处理XP系统响应速度慢
- 让xp文件下各种安全警告提示统统消失的妙招
- 让win xp系统定时关机的小妙招