(PECL ds >= 1.0.0)
Ds\Vector::insert — 在给定索引处插入值
index要插入的索引。0 <= index <= count
注意:
可以插入索引等于值的数量的索引。
values要插入的值或多个值。
不返回值。
如果索引无效,则抛出OutOfRangeException。
示例 #1 Ds\Vector::insert() 示例
<?php
$vector = new \Ds\Vector();
$vector->insert(0, "e"); // [e]
$vector->insert(1, "f"); // [e, f]
$vector->insert(2, "g"); // [e, f, g]
$vector->insert(0, "a", "b"); // [a, b, e, f, g]
$vector->insert(2, ...["c", "d"]); // [a, b, c, d, e, f, g]
var_dump($vector);
?>以上示例将输出类似以下内容
object(Ds\Vector)#1 (7) {
[0]=>
string(1) "a"
[1]=>
string(1) "b"
[2]=>
string(1) "c"
[3]=>
string(1) "d"
[4]=>
string(1) "e"
[5]=>
string(1) "f"
[6]=>
string(1) "g"
}