Monday, January 6, 2025
Google search engine
HomeLanguagesPHP | DsDeque set() Function

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(["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);
  
?>


Output:

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


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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments