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
  • References
  1. 📖Methods
  2. ⚡Static method

static from()

The from() static method creates a new, shallow-copied ArrayUtils instance from an iterable.

Previous⚡Static methodNextstatic of()

Last updated 4 years ago

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

var_export(ArrayUtils::from([3,6,9]));
// expected output: ArrayUtils(array(3, 6, 9))

var_export(ArrayUtils::from([1, 2, 3], function($x){ return $x + $x; }));
// expected output: ArrayUtils(array(2, 4, 9))

Syntax

ArrayUtils::from(iterable $iterable, ?callable $mapFn = null) : ArrayUtils

Parameter

  • $iterable

    Iterable object to convert to an array.

  • $mapFn

    Map function to call on every element of the array. Default is NULL . If is null, not execute map function.

Return value

  • A new ArrayUtils instance.

References

Array.from() - JavaScript | MDN
Logo