• PHP Video Tutorials

PHP - Ds Vector set() Function



Ds\Vector::set() function can update the value at a given index.

Syntax

public void Ds\Vector::set( int $index, mixed $value )

Ds\Vector::set() function doesn't return any value. This function can throw OutOfRangeException if an index is not valid.

Example 1

<?php 
   $vector = new \Ds\Vector([1, 2, 3, 4, 5]); 
   print_r($vector); 
  
   $vector->set(1, 10); 
   echo("\n The vector after updating an element: \n"); 
   print_r($vector); 
?>

Example 2

<?php 
   $vector = new \Ds\Vector(["Tutorials", "Point", "Tutorix"]); 
   print_r($vector); 
   
   $vector->set(1, "India"); 
   echo("\n The vector after updating an element: \n"); 
   print_r($vector); 
?>
php_function_reference.htm
Advertisements