当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP Ds Vector set()用法及代码示例



Ds\Vector::set() 函数可以更新给定索引处的值。

用法

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

Ds\Vector::set() 函数不返回任何值。如果索引无效,此函数可能会抛出 OutOfRangeException。

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

例子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 - Ds Vector set() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。