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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。