PHP | Ds\Deque set() Function
The Ds\Deque::set() function is an inbuilt function in PHP which is used to set the value at the given index in the Deque.
Syntax:
public Ds\Deque::set( $index, $value ) : void
Parameters: This function accept two parameters as mentioned above and described below:
- index: This parameter holds the index value on which the element is to be set.
- value: This parameter holds the value to be set at given index.
Return Value: This function does not return any value.
Below programs illustrate the Ds\Deque::set() function in PHP:
Program 1:
<?php // Declare a deque$deck = new \Ds\Deque(["geeks", "for", "geeks", "practice"]); echo("Elements of Deque\n"); // Display the Deque elementsprint_r($deck); // Updating the deque element at index 2$deck->set(2, "geeksforgeeks"); echo("Deque after setting value at index 2\n"); // Display the Deque elementsprint_r($deck); ?> |
Output:
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
)
Program 2:
<?php // Declare a deque$deck = new \Ds\Deque([1, 2, 3, 4, 5, 6]); echo("Elements of Deque\n"); // Display the Deque elementsprint_r($deck); // Updating the deque element at index 2$deck->set(4, 10); echo("Deque after setting value at index 2\n"); // Display the Deque elementsprint_r($deck); ?> |
Output:
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
)
Reference: http://php.net/manual/en/ds-deque.set.php


