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

pad()

The pad() method pad array to the specified length with a value

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

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

//Fill with 0 to have 10 elements
$arrayUtils->pad(10, 0);
// expected output: [1, 2, 3, 4, 5, 0, 0, 0, 0, 0]

//Fill with 0 to have 10 elements, append to front of array
$arrayUtils->pad(-10, 0);
// expected output: [0, 0, 0, 0, 0, 1, 2, 3, 4, 5]

Syntax

$arrayUtils->pad(int $size, mixed $value) : ArrayUtils;

Parameter

  • $size

    • New size of the array.

  • $value

    • Value to pad if array is less than size.

Return value

  • A padded array.

Prefixing

$arrayUtils->padAs(int $size, mixed $value) : array;
ArrayUtils::padFrom(iterable $from, int $size, mixed $value) : ArrayUtils;
ArrayUtils::padFromAs(iterable $from, int $size, mixed $value) : array;

References

PreviousmapKey()Nextpush()

Last updated 4 years ago

PHP: array_pad - Manual
Logo