Ds \ Vector::push()函数是PHP中的内置函数,用于将元素添加到向量的末尾。
用法:
void public Ds\Vector::push( $values )
参数:此函数接受单个参数$values,该参数包含一个或多个然后一个要添加到向量中的元素。
返回值:此函数不返回任何值。
以下示例程序旨在说明PHP中的Ds \ Vector::push()函数:
程序1:
<?php
// Create new vector
$arr1 = new \Ds\Vector([10, 20, 30, 40, 50]);
echo("Original vector elements\n");
print_r($arr1);
// Use push() function to add
// element to the vector
$arr1->push(60);
echo("\nVector after appending the elements\n");
print_r($arr1);
?>输出:
Original vector elements
Ds\Vector Object
(
[0] => 10
[1] => 20
[2] => 30
[3] => 40
[4] => 50
)
Vector after appending the elements
Ds\Vector Object
(
[0] => 10
[1] => 20
[2] => 30
[3] => 40
[4] => 50
[5] => 60
)
程序2:
<?php
// Create new vector
$arr1 = new \Ds\Vector([10, 20, 30, 40, 50]);
echo("Original vector elements\n");
print_r($arr1);
// Use push() function to add
// element to the vector
$arr1->push(...[60, 70]);
echo("\nVector after appending the elements\n");
print_r($arr1);
?>输出:
Original vector elements
Ds\Vector Object
(
[0] => 10
[1] => 20
[2] => 30
[3] => 40
[4] => 50
)
Vector after appending the elements
Ds\Vector Object
(
[0] => 10
[1] => 20
[2] => 30
[3] => 40
[4] => 50
[5] => 60
[6] => 70
)
参考: http://php.net/manual/en/ds-vector.push.php
相关用法
- PHP Ds\Deque push()用法及代码示例
- PHP Ds\PriorityQueue push()用法及代码示例
- PHP Ds\Queue push()用法及代码示例
- Node.js push()用法及代码示例
- PHP Ds\Sequence push()用法及代码示例
- PHP SplDoublyLinkedList push()用法及代码示例
- PHP Ds\Stack push()用法及代码示例
- p5.js value()用法及代码示例
注:本文由纯净天空筛选整理自barykrg大神的英文原创作品 PHP | Ds\Vector push() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
