PHP | Ds\Sequence set()函数
Ds\Sequence::set()函数是PHP中的一个内置函数,用于更新给定索引处的值。
句法:
void abstract public Ds\Sequence::set ( int $index , mixed $value )
参数:该函数接受上面提到的两个参数,如下所述:
- $index:用于保存要更新序列值的索引号。
- $value:用于保存要在给定索引处更新的新值。
返回值:该函数不返回任何值。
下面的程序说明了PHP中的Ds\Sequence::set()函数:
方案一:
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
)
方案二:
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