arrayutils
  • Home
  • 📖How to use?
    • âš¡Installation
  • 📖Methods
    • âš¡Static method
      • static from()
      • static of()
      • static mapToArray()
    • âš¡Generic method
      • join()
      • every()
      • some()
      • reduce()
        • reduceRight()
      • sum()
      • pop()
      • shift()
      • includes()
      • keyExists()
      • indexOf()
      • find()
        • findIndex()
      • first()
        • keyFirst()
      • last()
        • keyLast()
      • random()
        • keyRandom()
      • splice()
    • âš¡Chain method
      • chunk()
      • column()
      • combine()
      • concat()
        • concatSoft()
      • countValues()
      • diff()
        • diffAssoc()
        • diffKey()
      • fill()
        • fillKeys()
      • filter()
      • flat()
        • flatMap()
      • flip()
      • forEach()
      • intersect()
        • intersectAssoc()
        • intersectKey()
      • keys()
      • map()
        • mapAssoc()
        • mapKey()
      • pad()
      • push()
      • replace()
      • reverse()
      • slice()
      • sort()
        • sortKey()
      • unique()
      • unshift()
      • values()
  • 📖Suffixes
    • âš¡Suffix - From
    • âš¡Suffix - As
  • links
    • 📌Github repo
    • 📌Packagist project
    • 📌Poggit project
Powered by GitBook
On this page
  • Syntax
  • Parameter
  • Return value
  • Prefixing
  • References
  1. 📖Methods
  2. ⚡Chain method

unshift()

The unshift() method all similar to push(), but this push elements onto the start of array

Example.php
<?php use kim\present\utils\arrays\ArrayUtils;

$arrayUtils = ArrayUtils::from(range(1,5));

//Unshift 0 and 10
$arrayUtils->unshift(0, 10);
// expected output: [0, 10, 1, 2, 3, 4, 5]

Syntax

$arrayUtils->unshift(mixed ...$values) : ArrayUtils;

Parameter

  • $values

    A values to unshift into array

Return value

  • oneself back for method chaining.

Prefixing

$arrayUtils->unshiftAs(mixed ...$values) : array;
ArrayUtils::unshiftFrom(iterable $from, mixed ...$values) : ArrayUtils;
ArrayUtils::unshiftFromAs(iterable $from, mixed ...$values) : array;

References

Previousunique()Nextvalues()

Last updated 4 years ago

push()
Array.prototype.unshift() - JavaScript | MDN
PHP: array_unshift - Manual
Logo
Logo