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 mapToArray()

The mapToArray() static method cast all elements of the iterable to an array

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

ArrayUtils::mapToArray([
    1,
    [2, 3],
    new class()extends \StdClass{public $arrayStart = 0;},
    new ArrayObject([1, 2, 3, 4, 5]),
    new ArrayIterator(["ArrayUtils", "mapToArray"])
]));
// expected output: Array(
//                      Array(1),
//                      Array(2, 3),
//                      Array("arrayStart" => 0),
//                      Array(1, 2, 3, 4, 5),
//                      Array("ArrayUtils", "mapToArray")
//)

Syntax

ArrayUtils::mapToArray(iterable $iterables) : array

Parameter

  • $iterable

    An iterable containing an iterable. It converted to an array.

Return value

  • A new array containing elements converted to an array.

References

Previousstatic of()Next⚡Generic method

Last updated 4 years ago

PHP: Iterables - Manual
Logo