GoLang pht\Vector::insertAt

request it (367)
GoLang replacement for PHP's pht\Vector::insertAt [edit | history]



Do you know a GoLang replacement for PHP's pht\Vector::insertAt? Write it!

PHP pht\Vector::insertAt

PHP original manual for pht\Vector::insertAt [ show | php.net ]

pht\Vector::insertAt

(PECL pht >= 0.0.1)

pht\Vector::insertAtInserts a value into the vector

Description

public void pht\Vector::insertAt ( mixed $value , int $offset )

This method inserts a value at the specified offset into the vector (in linear time). The vector will automatically be resized if it is not large enough.

Parameters

value

The value to be inserted into the vector. This value will be serialised (since it may be passed around between threads).

offset

The offset at which the value will be inserted at. This offset must be within the 0..N range (inclusive), where N is the size of the vector. Inserting at position N is the equivalent of using pht\Vector::push(), and inserting at position 0 is the equivalent of using pht\Vector::unshift(). Attempting to insert at offsets outside of this range will result in an Error exception.

Return Values

No return value.

Examples

Example #1 Inserting a value into a vector

<?php

use pht\Vector;

$vector = new Vector();

$vector->insertAt(30); // insert 3 at start
$vector->insertAt(10); // insert 1 at start (before 3)
$vector->insertAt(21); // insert 2 in middle (after 1 and before 3)

var_dump($vector);

The above example will output:

object(pht\Vector)#1 (3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}