Ds \ Deque::unshift()函数是PHP中的一个内置函数,用于在双端队列前面添加值。
用法:
void Ds\Deque::unshift( $values )
参数:此函数接受单个参数$values,该参数包含要添加到双端队列的字体中的值。
返回值:此函数不返回任何值。
以下示例程序旨在说明PHP中的Ds \ Deque::unshift()函数:
程序1:
<?php
// Declare a deque
$deq = new \Ds\Deque([10, 20, 30, 40]);
// Use Ds\Deque::unshift() function
$deq -> unshift(5);
$deq -> unshift(7);
$deq -> unshift(8);
print_r($deq);
?>
输出:
Ds\Deque Object
(
[0] => 8
[1] => 7
[2] => 5
[3] => 10
[4] => 20
[5] => 30
[6] => 40
)
程序2:
<?php
// Declare a deque
$deq = new \Ds\Deque();
// Use Ds\Deque::unshift() function
$deq -> unshift("Welcome");
$deq -> unshift("to");
$deq -> unshift("GeeksforGeeks");
var_dump($deq);
// Declare another deque
$deq = new \Ds\Deque(['G', 'E', 'E', 'K', 'S']);
// Use Ds\Deque::unshift() function
$deq -> unshift("1");
$deq -> unshift("2");
$deq -> unshift("3");
var_dump($deq);
?>
输出:
object(Ds\Deque)#1 (3) {
[0]=>
string(13) "GeeksforGeeks"
[1]=>
string(2) "to"
[2]=>
string(7) "Welcome"
}
object(Ds\Deque)#2 (8) {
[0]=>
string(1) "3"
[1]=>
string(1) "2"
[2]=>
string(1) "1"
[3]=>
string(1) "G"
[4]=>
string(1) "E"
[5]=>
string(1) "E"
[6]=>
string(1) "K"
[7]=>
string(1) "S"
}
参考: https://www.php.net/manual/en/ds-deque.unshift.php
相关用法
- PHP Ds\Sequence unshift()用法及代码示例
- Node.js unshift()用法及代码示例
- PHP SplDoublyLinkedList unshift()用法及代码示例
- PHP Ds\Vector unshift()用法及代码示例
- p5.js arc()用法及代码示例
- p5.js log()用法及代码示例
- p5.js hex()用法及代码示例
- p5.js str()用法及代码示例
- PHP tan( )用法及代码示例
- d3.js d3.max()用法及代码示例
- p5.js red()用法及代码示例
- p5.js cos()用法及代码示例
注:本文由纯净天空筛选整理自jit_t大神的英文原创作品 PHP | Ds\Deque unshift() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
