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

fill()

The fill() method changes all values to a static value, from a start index to an end index

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

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

//Full fill with 0
$arrayUtils->fill(0);
// expected output: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

//Fill with 0 from position 2 until position 4
$arrayUtils->fill(0, 2, 4);
// expected output: [1, 2, 0, 0, 5, 6, 7, 8, 9, 10]

//Fill with 0 from position 4 until end
$arrayUtils->fill(0, 4);
// expected output: [1, 2, 3, 4, 0, 0, 0, 0, 0, 0]

Syntax

$arrayUtils->fill(mixed $value, int $start = 0, int $end = null) : ArrayUtils;

Parameter

  • $value

    Value to fill the array with.

  • Start index, default 0.

  • End index, default count($array).

Return value

  • A filled array.

Prefixing

$arrayUtils->fillAs(mixed $value, int $start = 0, int $end = null) : array;
ArrayUtils::fillFrom(iterable $from, mixed $value, int $start = 0, int $end = null) : ArrayUtils;
ArrayUtils::fillFromAs(iterable $from, mixed $value, int $start = 0, int $end = null) : array;

References

PreviousdiffKey()NextfillKeys()

Last updated 4 years ago

$start

$end

PHP: array_fill_keys - Manual
Logo