PHP | Ds\Deque set()函数
Ds\Deque::set()函数是PHP中的一个内置函数,用于设置 Deque 中给定索引处的值。
句法:
public Ds\Deque::set( $index, $value ) : void
参数:此函数接受上面提到的两个参数,如下所述:
- index:此参数保存要设置元素的索引值。
- value:此参数保存要在给定索引处设置的值。
返回值:此函数不返回任何值。
下面的程序说明了PHP中的Ds\Deque::set()函数:
方案一:
set(2, "geeksforgeeks");
echo("Deque after setting value at index 2\n");
// Display the Deque elements
print_r($deck);
?>
输出:
Elements of Deque
Ds\Deque Object
(
[0] => geeks
[1] => for
[2] => geeks
[3] => practice
)
Deque after setting value at index 2
Ds\Deque Object
(
[0] => geeks
[1] => for
[2] => geeksforgeeks
[3] => practice
)
方案二:
set(4, 10);
echo("Deque after setting value at index 2\n");
// Display the Deque elements
print_r($deck);
?>
输出:
Elements of Deque
Ds\Deque Object
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
)
Deque after setting value at index 2
Ds\Deque Object
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 10
[5] => 6
)
参考: http: PHP。 PHP