Skip to content

array_list

Description

Return a collection based on type.

Usage

<?php

use Qubus\Support\Collection\ArrayList;

use function Qubus\Support\Helpers\array_list;

function array_list(string $type): ArrayList;

Parameters

$type (string) (required) The type of array values expected.

Return Value

(string) A collection.

Example

<?php

use function Qubus\Support\Helpers\array_list;

$callables = [
    fn() => 'Hello World!',
    fn() => 'I love programming!',
    fn() => 'I love PHP!'
];

$list = array_list('callable');
foreach ($callables as $callable) {
    $list->add($callable);
}

echo $list->type(); // callable
// or
echo $list->all()[2](); // I love PHP!

Go Further

To use the array_list() helper beyond the example above, check out Collections. The array_list() helper and the collect() helper inherit some of the same methods but may return different results. Another difference is that collect() can return a mixture of primitives and data structures, while array_list() returns an array of the same specified primitive type.