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 elements print_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 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 )
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
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- How to get the function name inside a function in PHP ?
- PHP | pos() Function
- PHP | key() Function
- D3.js | d3.map.set() Function
- PHP | Ds\Set add() Function
- PHP | end() Function
- p5.js | log() function
- p5.js | sin() function
- p5.js | cos() function
- PHP | Ds\Map xor() Function
- PHP | abs() Function
- p5.js | max() function
- D3.js | d3.hcl() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.