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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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);
  
?>

chevron_right


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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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);
  
?>

chevron_right


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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.