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([ "neveropen" , "for" , "neveropen" , "practice" ]); echo ( "Elements of Deque\n" ); // Display the Deque elements print_r( $deck ); // Updating the deque element at index 2 $deck ->set(2, "neveropen" ); echo ( "Deque after setting value at index 2\n" ); // Display the Deque elements print_r( $deck ); ?> |
Elements of Deque Ds\Deque Object ( [0] => neveropen [1] => for [2] => neveropen [3] => practice ) Deque after setting value at index 2 Ds\Deque Object ( [0] => neveropen [1] => for [2] => neveropen [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 elements print_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 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 )
Reference: http://php.net/manual/en/ds-deque.set.php