PHP | Ds\Vector set() Function Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The Ds\Vector::set() function is an inbuilt function in PHP which is used to set the value in the vector at the given index. Syntax: void public Ds\Vector::set( $index, $value ) Parameters: This function accepts two parameters as mentioned above and described below: $index: This parameter holds the index value at which the vector value to be updated. $value: This parameter holds the value by which previous element is to be replaced. Return Value: This function does not return any value. Exception: This function throws OutOfRangeException if index is invalid. Below programs illustrate the Ds\Vector::set() function in PHP: Program 1: PHP <?php // Create new Vector $vect = new \Ds\Vector([1, 2, 3, 4, 5]); // Display the Vector elements print_r($vect); // Use set() function to set the // element in the vector $vect->set(1, 10); echo("\nVector after updating the element\n"); // Display the vector elements print_r($vect); ?> Output: Ds\Vector Object ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 ) Vector after updating the element Ds\Vector Object ( [0] => 1 [1] => 10 [2] => 3 [3] => 4 [4] => 5 ) Program 2: PHP <?php // Create new Vector $vect = new \Ds\Vector(["geeks", "of", "geeks"]); // Display the Vector elements print_r($vect); // Use set() function to set the // element in the vector $vect->set(1, "for"); echo("\nVector after updating the element\n"); // Display the vector elements print_r($vect); ?> Output: Ds\Vector Object ( [0] => geeks [1] => of [2] => geeks ) Vector after updating the element Ds\Vector Object ( [0] => geeks [1] => for [2] => geeks ) Reference: https://www.php.net/manual/en/ds-vector.set.php Comment More infoAdvertise with us Next Article PHP | Ds\Vector slice() Function B barykrg Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_vector Similar Reads PHP | Ds\Vector sort() Function The Ds\Vector::sort() function is an inbuilt function in PHP which is used to sort the elements of vector in-place. This will arrange the vector elements in increasing order. Syntax: void public Ds\Vector::sort( $comparator ) Parameters: This function accepts a single parameter $comparator which is 2 min read PHP | Ds\Vector sort() Function The Ds\Vector::sort() function is an inbuilt function in PHP which is used to sort the elements of vector in-place. This will arrange the vector elements in increasing order. Syntax: void public Ds\Vector::sort( $comparator ) Parameters: This function accepts a single parameter $comparator which is 2 min read PHP | Ds\Vector shift() Function The Ds\Vector::shift() function is an inbuilt function in PHP which is used to remove the first element from the vector and return it. Syntax: mixed public Ds\Vector::shift( void ) Parameters: This function does not accept any parameter. Return Value: This function returns the value at index 0. Exce 1 min read PHP | Ds\Vector shift() Function The Ds\Vector::shift() function is an inbuilt function in PHP which is used to remove the first element from the vector and return it. Syntax: mixed public Ds\Vector::shift( void ) Parameters: This function does not accept any parameter. Return Value: This function returns the value at index 0. Exce 1 min read PHP | Ds\Vector slice() Function The Ds\Vector::slice() function is an inbuilt function in PHP which is used to return the sub-vector of the given vector. Syntax: Ds\Vector public Ds\Vector::slice( $index, $length )/pre> Parameters: This function accepts two parameter as mentioned above and described below: $index: This parameter h 2 min read PHP | Ds\Vector slice() Function The Ds\Vector::slice() function is an inbuilt function in PHP which is used to return the sub-vector of the given vector. Syntax: Ds\Vector public Ds\Vector::slice( $index, $length )/pre> Parameters: This function accepts two parameter as mentioned above and described below: $index: This parameter h 2 min read Like