GoLang pht\Vector::unshift

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



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

PHP pht\Vector::unshift

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

pht\Vector::unshift

(PECL pht >= 0.0.1)

pht\Vector::unshiftUnshifts a value to the vector front

Description

public void pht\Vector::unshift ( mixed $value )

This method unshifts a value to the front of a vector (in linear time). The vector will automatically be resized if it is not large enough.

Parameters

value

The value to be pushed onto the beginning of the vector. This value will be serialised (since it may be passed around between threads).

Return Values

No return value.

Examples

Example #1 Unshifting a value to the front of a vector

<?php

use pht\Vector;

$vector = new Vector();

for (
$i 0$i 3; ++$i) {
    
$vector->unshift($i); // causes a quadratic runtime, beware
}

var_dump($vector);

The above example will output:

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