Ds \ Sequence::set()函数是PHP中的内置函数,用于更新给定索引处的值。
用法:
void abstract public Ds\Sequence::set ( int $index , mixed $value )
参数:该函数接受上述和以下描述的两个参数:
- $index:它用于保存要更新的序列值的索引号。
 - $value:它用于保存要在给定索引处更新的新值。
 
返回值:该函数不返回任何值。
以下示例程序旨在说明PHP中的Ds \ Sequence::set()函数:
程序1:
<?php  
  
// Create new Sequence 
$seq = new \Ds\Vector([1, 2, 3, 4, 5]);  
  
echo("Original Sequence\n");  
  
// Display the Sequence elements  
print_r($seq);  
  
// Use set() function to update 
// the sequence elements  
$seq->set(2, "Geeks"); 
  
echo("\nSequence after updating the elements\n");  
  
// Display the Sequence elements  
print_r($seq);  
  
?> 
输出:
Original Sequence
Ds\Vector Object
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
)
Sequence after updating the elements
Ds\Vector Object
(
    [0] => 1
    [1] => 2
    [2] => Geeks
    [3] => 4
    [4] => 5
)
程序2:
<?php  
  
// Create new Sequence 
$seq = new \Ds\Vector(["Geeks", "for", "Geeks",  
        "Computer", "Science", "Portal"]);  
  
echo("Original Sequence\n");  
  
// Display the Sequence elements  
print_r($seq);  
  
// Use set() function to set 
// the sequence elements  
$seq->set(0, "Welcome"); 
$seq->set(1, "to"); 
$seq->set(2, "GeeksforGeeks"); 
  
echo("\nSequence after updating the elements\n");  
  
// Display the Sequence elements  
print_r($seq);  
  
?> 
输出:
Original Sequence
Ds\Vector Object
(
    [0] => Geeks
    [1] => for
    [2] => Geeks
    [3] => Computer
    [4] => Science
    [5] => Portal
)
Sequence after updating the elements
Ds\Vector Object
(
    [0] => Welcome
    [1] => to
    [2] => GeeksforGeeks
    [3] => Computer
    [4] => Science
    [5] => Portal
)
参考: https://www.php.net/manual/en/ds-sequence.set.php
相关用法
- d3.js d3.lab()用法及代码示例
 - PHP exp()用法及代码示例
 - PHP Ds\Map put()用法及代码示例
 - d3.js d3.hcl()用法及代码示例
 - PHP sin( )用法及代码示例
 - PHP abs()用法及代码示例
 - PHP cos( )用法及代码示例
 - PHP tan( )用法及代码示例
 - d3.js d3.map.set()用法及代码示例
 - PHP next()用法及代码示例
 - PHP Ds\Map get()用法及代码示例
 - d3.js d3.sum()用法及代码示例
 
注:本文由纯净天空筛选整理自R_Raj大神的英文原创作品 PHP | Ds\Sequence set() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
