arrayutils
Search…
static from()
The from() static method creates a new, shallow-copied ArrayUtils instance from an iterable.
Example.php
1
<?php use kim\present\utils\arrays\ArrayUtils;
2
3
var_export(ArrayUtils::from([3,6,9]));
4
// expected output: ArrayUtils(array(3, 6, 9))
5
6
var_export(ArrayUtils::from([1, 2, 3], function($x){ return $x + $x; }));
7
// expected output: ArrayUtils(array(2, 4, 9))
Copied!

Syntax

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

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