Ds \ Vector::set()函数是PHP中的一个内置函数,用于在给定索引处设置向量中的值。
用法:
void public Ds\Vector::set( $index, $value )
参数:该函数接受上述和以下描述的两个参数:
- $index:此参数保存要更新矢量值的索引值。
- $value:此参数保存将替换先前元素的值。
返回值:该函数不返回任何值。
异常:如果索引无效,此函数将抛出OutOfRangeException。
以下示例程序旨在说明PHP中的Ds \ Vector::set()函数:
程序1:
<?php
// Create new Vector
$vect = new \Ds\Vector([1, 2, 3, 4, 5]);
// Display the Vector elements
print_r($vect);
// Use set() function to set the
// element in the vector
$vect->set(1, 10);
echo("\nVector after updating the element\n");
// Display the vector elements
print_r($vect);
?>输出:
Ds\Vector Object
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
)
Vector after updating the element
Ds\Vector Object
(
[0] => 1
[1] => 10
[2] => 3
[3] => 4
[4] => 5
)
程序2:
<?php
// Create new Vector
$vect = new \Ds\Vector(["geeks", "of", "geeks"]);
// Display the Vector elements
print_r($vect);
// Use set() function to set the
// element in the vector
$vect->set(1, "for");
echo("\nVector after updating the element\n");
// Display the vector elements
print_r($vect);
?>输出:
Ds\Vector Object
(
[0] => geeks
[1] => of
[2] => geeks
)
Vector after updating the element
Ds\Vector Object
(
[0] => geeks
[1] => for
[2] => geeks
)
参考: http://php.net/manual/en/ds-vector.set.php
相关用法
- p5.js str()用法及代码示例
- p5.js min()用法及代码示例
- PHP end()用法及代码示例
- PHP sin( )用法及代码示例
- PHP cos( )用法及代码示例
- p5.js hue()用法及代码示例
- PHP pos()用法及代码示例
- p5.js hex()用法及代码示例
- p5.js red()用法及代码示例
- p5.js tan()用法及代码示例
- p5.js log()用法及代码示例
- p5.js sin()用法及代码示例
注:本文由纯净天空筛选整理自barykrg大神的英文原创作品 PHP | Ds\Vector set() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
