PHPackages                             dezworkastronphp/collection - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. dezworkastronphp/collection

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dezworkastronphp/collection
===========================

better abstraction of array built in type

v2.2.0(3y ago)0101MITPHPPHP ^7.0

Since May 4Pushed 3y ago1 watchersCompare

[ Source](https://github.com/dezworkastronphp/collection)[ Packagist](https://packagist.org/packages/dezworkastronphp/collection)[ RSS](/packages/dezworkastronphp-collection/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (2)Versions (4)Used By (1)

Collection
==========

[](#collection)

[![](https://camo.githubusercontent.com/03b25a43a96d753d006aa996e2f814df80620cac54d4e1448ab98e097d1c71f0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f617374726f6e7068702f636f6c6c656374696f6e2e737667)](https://packagist.org/packages/astronphp/collection)[![](https://camo.githubusercontent.com/e3ab47ea23f8151d32c33c1a8b9cbe9cef8a9d2660c44654b6922d75575b9f3d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f617374726f6e7068702f636f6c6c656374696f6e2e737667)](https://packagist.org/packages/astronphp/collection)[![](https://camo.githubusercontent.com/ed5fe8eb6779b442f8f2bc8e621a6e9a65200c7cac8e1d6561290a5c720819aa/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f617374726f6e7068702f636f6c6c656374696f6e2e737667)](https://raw.githubusercontent.com/astronphp/collection/master/LICENSE)[![](https://camo.githubusercontent.com/9b4fecda5cf8b57c86e434dd7df8a880aee9d863b8786075f34830e5e438e85b/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f617374726f6e7068702f636f6c6c656374696f6e2e737667)](https://travis-ci.org/astronphp/collection)[![](https://camo.githubusercontent.com/783a0dbdfb2e2a369afaad712db77a172fb4408ec8c52fe71490f542494f6c02/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f617374726f6e7068702f636f6c6c656374696f6e2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/astronphp/collection)[![](https://camo.githubusercontent.com/df0bb44b4516dc297a674c72735cd810d990de7c66a4316d8254b777dce1cf94/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f617374726f6e7068702f636f6c6c656374696f6e2e737667)](https://github.com/astronphp/collection/issues)[![](https://camo.githubusercontent.com/f1750f4e062fd4bcd0ecc3b762de503310f352464d9427bee923de9e69e25f59/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f617374726f6e7068702f636f6c6c656374696f6e2e737667)](https://github.com/astronphp/collection/graphs/contributors)

Instalação
----------

[](#instalação)

`composer require astronphp/collection`

Guia do Usuário
---------------

[](#guia-do-usuário)

- [\_\_construct](#construct)
- [unshift](#unshift)
- [push](#push)
- [set](#set)
- [get](#get)
- [isset](#isset)
- [empty](#empty)
- [unset](#unset)
- [length](#length)
- [shift](#shift)
- [pop](#pop)
- [first](#first)
- [last](#last)
- [each](#each)
- [for](#for)
- [walk](#walk)
- [sum](#sum)
- [contains](#contains)
- [map](#map)
- [filter](#filter)
- [reduce](#reduce)
- [join](#join)
- [random](#random)
- [shuffle](#shuffle)
- [flip](#flip)
- [keys](#keys)
- [values](#values)
- [column](#column)
- [chunk](#chunk)
- [unique](#unique)
- [coalesce](#coalesce)
- [merge](#merge)
- [reverse](#reverse)
- [search](#search)
- [lower](#lower)
- [upper](#upper)
- [toArray](#toarray)
- [toJson](#tojson)
- [sort](#sort)
- [rsort](#rsort)
- [asort](#asort)
- [arsort](#arsort)
- [ksort](#ksort)
- [krsort](#krsort)
- [union](#union)
- [diff](#diff)
- [outer](#outer)
- [intersect](#intersect)
- [cartesian](#cartesian)
- [isCollection](#iscollection)
- [combine](#combine)
- [range](#range)

construct
---------

[](#construct)

```
public function __construct($content = [])
```

Recebe opcionalmente um array ou um objeto, que será convertido internamente.

```
use Astronphp\Collection\Collection;

$collection1 = new Collection();
$collection2 = new Collection(['lorem' => 'ipsum']);
$collection3 = new Collection(new \DateTime('now'));

var_dump($collection1, $collection2, $collection3);

/*
object(Astronphp\Collection\Collection)[3]
  protected 'content' => array (size = 0)
  protected 'length'  => int 0

object(Astronphp\Collection\Collection)[2]
  protected 'content' => array (size=1)
    'lorem' => string 'ipsum' (length=5)
  protected 'length' => int 1

object(Astronphp\Collection\Collection)[4]
  protected 'content' => array (size=3)
      'date' => string '2019-09-17 14:42:47.000000' (length=26)
      'timezone_type' => int 3
      'timezone' => string 'UTC' (length=3)
  protected 'length' => int 3
*/
```

unshift
-------

[](#unshift)

```
public function unshift(...$values): self
```

Adiciona valores no início da coleção.

```
use Astronphp\Collection\Collection;

$collection = new Collection();
$collection->unshift('lorem');
$collection->unshift('ipsum', 'dolor');

var_dump($collection);

/*
object(Astronphp\Collection\Collection)[3]
  protected 'content' =>
    array (size=3)
      0 => string 'ipsum' (length=5)
      1 => string 'dolor' (length=5)
      2 => string 'lorem' (length=5)
  protected 'length' => int 3
*/
```

push
----

[](#push)

```
public function push(...$values): self
```

Adiciona valores ao final da coleção.

```
use Astronphp\Collection\Collection;

$collection = new Collection();
$collection->push('lorem');
$collection->push('ipsum', 'dolor');

var_dump($collection);

/*
object(Astronphp\Collection\Collection)[3]
  protected 'content' =>
    array (size=3)
      0 => string 'lorem' (length=5)
      1 => string 'ipsum' (length=5)
      2 => string 'dolor' (length=5)
  protected 'length' => int 3
*/
```

set
---

[](#set)

```
public function set(string $key, $value): self
```

Associa uma chave à um valor.

```
use Astronphp\Collection\Collection;

$collection = new Collection();
$collection->set('lorem', 'ipsum');
$collection->set('dolor.amet', 'consectetur');

var_dump($collection);

/*
object(Astronphp\Collection\Collection)[3]
  protected 'content' =>
    array (size=2)
      'lorem' => string 'ipsum' (length=5)
      'dolor' =>
        array (size=1)
          'amet' => string 'consectetur' (length=11)
  protected 'length' => int 2
*/
```

get
---

[](#get)

```
public function get(string $key)
```

Recupera valores da coleção

```
use Astronphp\Collection\Collection;

$collection = new Collection();
$collection->set('lorem', 'ipsum');
$collection->set('dolor.amet', 'consectetur');

$collection->get('lorem'); // ipsum
$collection->get('dolor.amet'); // consectetur
```

isset
-----

[](#isset)

```
public function isset(string $key): bool
```

Verifica chaves não inicializadas ou com valor nulo

```
use Astronphp\Collection\Collection;

$collection = new Collection();
$collection->set('lorem', 'ipsum');

$collection->isset('lorem'); // true
$collection->isset('dolor'); // false
```

empty
-----

[](#empty)

```
public function empty(string $key): bool
```

Verifica chaves vazias

```
use Astronphp\Collection\Collection;

$collection = new Collection();

$collection->set('lorem', 1);
$collection->set('ipsum', 0);

$collection->empty('lorem'); // false
$collection->empty('ipsum'); // true
```

unset
-----

[](#unset)

```
public function unset(string $key)
```

Remove chaves

```
use Astronphp\Collection\Collection;

$collection = new Collection();
$collection->set('lorem', 'ipsum');

var_dump($collection);

/*
object(Astronphp\Collection\Collection)[3]
  protected 'content' =>
    array (size=1)
      'lorem' => string 'ipsum' (length=5)
  protected 'length' => int 1
*/

$collection->unset('lorem');

var_dump($collection);

/*
object(Astronphp\Collection\Collection)[3]
  protected 'content' =>
    array (size=0)
      empty
  protected 'length' => int 0
*/
```

length
------

[](#length)

```
public function length(): int
```

Recupera o tamanho da coleção

```
use Astronphp\Collection\Collection;

$collection = new Collection([1, 2, 3, 4, 5]);
$collection->length(); // 5
```

shift
-----

[](#shift)

```
public function shift()
```

Remove o primeiro elemento da coleção retornando o elemento removido

```
use Astronphp\Collection\Collection;

$collection = new Collection([1, 2, 3, 4, 5]);
$collection->shift(); // 1
```

pop
---

[](#pop)

```
public function pop()
```

Remove o ultimo elemento da coleção retornando o elemento removido

```
use Astronphp\Collection\Collection;

$collection = new Collection([1, 2, 3, 4, 5]);
$collection->pop(); // 5
```

first
-----

[](#first)

```
public function first()
```

Recupera o primeiro item da coleção

```
use Astronphp\Collection\Collection;

$collection = new Collection([1, 2, 3, 4, 5]);
$collection->first(); // 1
```

last
----

[](#last)

Recupera o último item da coleção

```
public function last()
```

```
use Astronphp\Collection\Collection;

$collection = new Collection([1, 2, 3, 4, 5]);
$collection->last(); // 5
```

each
----

[](#each)

```
public function each(callable $callback)
```

Percorre toda a coleção

```
use Astronphp\Collection\Collection;

$collection = new Collection(['lorem' => 'ipsum', 'dolor' => 'amet']);
$collection->each(function($key, $value) {
    var_dump($key, $value);
});

/*
string 'lorem' (length=5)
string 'ipsum' (length=5)

string 'dolor' (length=5)
string 'amet' (length=4)
*/
```

for
---

[](#for)

```
public function for(int $start, int $step, callable $callback)
```

Percorre a coleção em passos

```
use Astronphp\Collection\Collection;

$collection = new Collection([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
$collection->for(0, 2, function($key, $value) {
    var_dump($value);
});

/* int 0, int 2, int 4, int 6, int 8, int 10 */
```

walk
----

[](#walk)

Percorre a coleção recursivamente

```
public function walk(callable $callback, $type = \RecursiveIteratorIterator::LEAVES_ONLY)
```

```
use Astronphp\Collection\Collection;

$collection = new Collection(['lorem', ['ipsum', 'dolor'], ['sit' => ['amet' => 'consectetur']]]);
$collection->walk(function($key, $value) {
    var_dump($key, $value);
});

/*
int 0
string 'lorem' (length=5)
int 0
string 'ipsum' (length=5)
int 1
string 'dolor' (length=5)
string 'amet' (length=4)
string 'consectetur' (length=11)
*/
```

sum
---

[](#sum)

```
public function sum()
```

Soma todos os elementos da coleção

```
use Astronphp\Collection\Collection;

$collection = new Collection([1, 2, 3, 4, 5]);
$collection->sum(); // 15
```

contains
--------

[](#contains)

```
public function contains($value): bool
```

Verifica se um dado valor existe na coleção

```
use Astronphp\Collection\Collection;

$collection = new Collection(['lorem', 'ipsum', 'dolor']);
$collecion->contains('dolor'); // true
```

map
---

[](#map)

```
public function map(callable $callback): self
```

Aplica um callback em todos os elementos da coleção

```
use Astronphp\Collection\Collection;

$collection = new Collection(['lorem', 'ipsum', 'dolor']);
var_dump($collection->map(function($key, $value) {
    return [$key => strtoupper($value)];
}));

/*
object(Astronphp\Collection\Collection)[4]
  protected 'content' =>
    array (size=3)
      0 => string 'LOREM' (length=5)
      1 => string 'IPSUM' (length=5)
      2 => string 'DOLOR' (length=5)
  protected 'length' => int 3
*/
```

filter
------

[](#filter)

```
public function filter(callable $callback): self
```

Filtra a coleção utilizando um callback

```
use Astronphp\Collection\Collection;

$collection = new Collection([1, 2, 3, 4, 5, 6, 7, 8, 9]);
var_dump($collection->filter(function($key, $value) {
    return $value > 5;
}));

/*
object(Astronphp\Collection\Collection)[4]
  protected 'content' =>
    array (size=4)
      5 => int 6
      6 => int 7
      7 => int 8
      8 => int 9
  protected 'length' => int 4
*/
```

reduce
------

[](#reduce)

```
public function reduce(callable $callback): self
```

Reduz a coleção a um único valor

```
use Astronphp\Collection\Collection;

$collection = new Collection([1, 2, 3, 4, 5]);
$result     = $collection->reduce(function($a, $b) {
    return $a + $b;
});

var_dump($result); // int 15
```

join
----

[](#join)

```
public function join(string $glue)
```

Junta os elementos em uma string

```
use Astronphp\Collection\Collection;

$collection = new Collection([1, 2, 3, 4, 5]);
var_dump($collection->join('-')); // string '1-2-3-4-5'
```

random
------

[](#random)

```
public function random(int $num = 1)
```

Recupera elementos aleatórios da coleção

```
use Astronphp\Collection\Collection;

$collection = new Collection([1, 2, 3, 4, 5]);
$collection->random(); // 3
```

shuffle
-------

[](#shuffle)

```
public function shuffle(): self
```

Embaralha os elementos da coleção

```
use Astronphp\Collection\Collection;

$collection = new Collection([1, 2, 3, 4, 5]);
var_dump($collection->shuffle());

/*
object(Astronphp\Collection\Collection)[2]
  protected 'content' =>
    array (size=5)
      0 => int 3
      1 => int 1
      2 => int 5
      3 => int 2
      4 => int 4
  protected 'length' => int 5
*/
```

flip
----

[](#flip)

```
public function flip(): self
```

Inverte a relação entre chaves e valores da coleção

```
use Astronphp\Collection\Collection;

$collection = new Collection(['lorem', 'ipsum', 'dolor']);
var_dump($collection->flip());

/*
object(Astronphp\Collection\Collection)[2]
  protected 'content' =>
    array (size=3)
      'lorem' => int 0
      'ipsum' => int 1
      'dolor' => int 2
  protected 'length' => int 3
*/
```

keys
----

[](#keys)

```
public function keys(): self
```

Retorna uma coleção apenas com as chaves da coleção anterior

```
use Astronphp\Collection\Collection;

$collection = new Collection(['lorem' => 'ipsum', 'dolor' => 'amet']);
var_dump($collection->keys());

/*
object(Astronphp\Collection\Collection)[2]
  protected 'content' =>
    array (size=2)
      0 => string 'lorem' (length=5)
      1 => string 'dolor' (length=5)
  protected 'length' => int 2
*/
```

values
------

[](#values)

```
public function values(): self
```

Retorna uma coleção apenas com os valores da coleção anterior

```
use Astronphp\Collection\Collection;

$collection = new Collection(['lorem' => 'ipsum', 'dolor', 'amet']);
var_dump($collection->values());

/*
object(Astronphp\Collection\Collection)[2]
  protected 'content' =>
    array (size=2)
      0 => string 'ipsum' (length=5)
      1 => string 'amet' (length=4)
  protected 'length' => int 2
*/
```

column
------

[](#column)

```
public function column($key, $index = null)
```

Recupera dados de uma coluna da coleção

```
use Astronphp\Collection\Collection;

$collection = new Collection([
    [
        'lorem' => 'ipsum',
        'dolor' => 'amet',
    ],
    [
        'lorem' => 'dolor',
        'dolor' => 'consectetur',
    ],
]);

var_dump($collection->column('lorem'));

/*
object(Astronphp\Collection\Collection)[2]
  protected 'content' =>
    array (size=2)
      0 => string 'ipsum' (length=5)
      1 => string 'dolor' (length=5)
  protected 'length' => int 2
*/
```

chunk
-----

[](#chunk)

```
public function chunk(int $size, bool $preserve_keys = false): self
```

Divide a coleção em partes iguais

```
use Astronphp\Collection\Collection;

$collection = new Collection([1, 2, 3, 4, 5, 6, 7, 8, 9]);
var_dump($collection->chunk(3));

/*
object(Astronphp\Collection\Collection)[2]
  protected 'content' =>
    array (size=3)
      0 =>
        array (size=3)
          0 => int 1
          1 => int 2
          2 => int 3
      1 =>
        array (size=3)
          0 => int 4
          1 => int 5
          2 => int 6
      2 =>
        array (size=3)
          0 => int 7
          1 => int 8
          2 => int 9
  protected 'length' => int 3
*/
```

unique
------

[](#unique)

```
public function unique(int $flags = SORT_STRING): self
```

Remove duplicatas

```
use Astronphp\Collection\Collection;

$collection = new Collection([1, 2, 3, 1, 2, 3, 4, 5, 2, 3, 4]);
var_dump($collection->unique());

/*
object(Astronphp\Collection\Collection)[2]
  protected 'content' =>
    array (size=5)
      0 => int 1
      1 => int 2
      2 => int 3
      6 => int 4
      7 => int 5
  protected 'length' => int 5
*/
```

coalesce
--------

[](#coalesce)

```
public function coalesce()
```

Retorna o primeiro valor não nulo encontrado

```
use Astronphp\Collection\Collection;

$collection = new Collection([null, null, null, 'lorem', null, null]);
var_dump($collection->coalesce()); // string 'lorem'
```

merge
-----

[](#merge)

```
public function merge();
```

Mescla todas as dimensões da coleção

```
use Astronphp\Collection\Collection;

$collection = new Collection([
    ['lorem' => 'ipsum'],
    ['dolor' => 'sit'],
    ['amet'  => 'consectetur'],
]);

var_dump($collection->merge());

/*
object(Astronphp\Collection\Collection)[4]
  protected 'content' =>
    array (size=3)
      'lorem' => string 'ipsum' (length=5)
      'dolor' => string 'sit' (length=3)
      'amet' => string 'consectetur' (length=11)
  protected 'length' => int 3
*/
```

reverse
-------

[](#reverse)

```
public function reverse($preserve_keys = null): self
```

Inverte a coleção

```
use Astronphp\Collection\Collection;

$collection = new Collection([1, 2, 3, 4, 5]);
var_dump($collection->reverse());

/*
object(Astronphp\Collection\Collection)[2]
  protected 'content' =>
    array (size=5)
      0 => int 5
      1 => int 4
      2 => int 3
      3 => int 2
      4 => int 1
  protected 'length' => int 5
*/
```

search
------

[](#search)

```
public function search($value, bool $strict = null)
```

Retorna a chave do valor solicitado

```
use Astronphp\Collection\Collection;

$collection = new Collection(['lorem' => 'ipsum', 'dolor' => 'amet']);
var_dump($collection->search('ipsum')); // 'lorem'
```

lower
-----

[](#lower)

```
public function lower(): self
```

Transforma recursivamente o case de todas as chaves da coleção para minúsculo

```
use Astronphp\Collection\Collection;

$collection = new Collection(['Lorem' => 'Ipsum', 'Dolor' => 'Amet']);
var_dump($collection->upper());

/*
object(Astronphp\Collection\Collection)[3]
  protected 'content' =>
    array (size=2)
      'LOREM' => string 'Ipsum' (length=5)
      'DOLOR' => string 'Amet' (length=4)
  protected 'length' => int 2
*/
```

upper
-----

[](#upper)

```
public function upper(): self
```

Transforma recursivamente o case de todas as chaves da coleção para maiúsculo

```
use Astronphp\Collection\Collection;

$collection = new Collection(['Lorem' => 'Ipsum', 'Dolor' => 'Amet']);
var_dump($collection->lower());

/*
object(Astronphp\Collection\Collection)[3]
  protected 'content' =>
    array (size=2)
      'lorem' => string 'Ipsum' (length=5)
      'dolor' => string 'Amet' (length=4)
  protected 'length' => int 2
*/
```

toArray
-------

[](#toarray)

```
public function toArray()
```

Recupera o array interno da coleção

```
use Astronphp\Collection\Collection;

$collection = new Collection([1, 2, 3, 4, 5]);
var_dump($collection->toArray());

/*
array (size=5)
  0 => int 1
  1 => int 2
  2 => int 3
  3 => int 4
  4 => int 5
*/
```

toJson
------

[](#tojson)

```
public function toJson()
```

Retorna o conteúdo da coleção em uma string JSON

```
use Astronphp\Collection\Collection;

$collection = new Collection(['lorem' => 'ipsum', 'dolor' => 'amet']);
var_dump($collection->toJson()); // string '{"lorem":"ipsum","dolor":"amet"}'
```

sort
----

[](#sort)

```
public function sort()
```

Ordena os valores da coleção

```
use Astronphp\Collection\Collection;

$collection = new Collection([3, 4, 8, 7, 1, 5]);
$collection->sort(); //[1,3,4,5,7,8]
```

rsort
-----

[](#rsort)

```
public function rsort()
```

Ordena os valores da coleção em ordem inversa

```
use Astronphp\Collection\Collection;

$collection = new Collection([3, 4, 8, 7, 1, 5]);
$collection->rsort(); //[8,7,5,4,3,1]
```

asort
-----

[](#asort)

```
public function asort()
```

Ordena os valores da coleção mantendo a associação

```
use Astronphp\Collection\Collection;

$collection = new Collection([
    'lorem' => 'ipsum',
    'dolor' => 'amet',
    'sit' => 'consectetur'
]);
$collection->asort(); //["dolor" => "amet","sit" => "consectetur","lorem" => "ipsum"]
```

arsort
------

[](#arsort)

```
public function arsort()
```

Ordena os valores da coleção em ordem inversa mantendo a associação

```
use Astronphp\Collection\Collection;

$collection = new Collection([
    'lorem' => 'ipsum',
    'dolor' => 'amet',
    'sit' => 'consectetur'
]);
$collection->arsort(); // ["lorem" => "ipsum","sit" => "consectetur","dolor" => "amet"]
```

ksort
-----

[](#ksort)

```
public function ksort()
```

Ordena os valores da coleção pelas chaves

```
use Astronphp\Collection\Collection;

$collection = new Collection([
    'lorem' => 'ipsum',
    'dolor' => 'amet',
    'sit' => 'consectetur'
]);
$collection->ksort(); //["dolor" => "amet","lorem" => "ipsum","sit" => "consectetur"]
```

krsort
------

[](#krsort)

```
public function krsort()
```

Ordena os valores da coleção pelas chaves em ordem inversa

```
use Astronphp\Collection\Collection;

$collection = new Collection([
    'lorem' => 'ipsum',
    'dolor' => 'amet',
    'sit' => 'consectetur'
]);
$collection->krsort(); //["sit" => "consectetur","lorem" => "ipsum","dolor" => "amet"]
```

union
-----

[](#union)

```
public function union()
```

Realiza a união entre todos os conjuntos da coleção

```
use Astronphp\Collection\Collection;

$collection = new Collection([
    [1, 2, 3],
    [3, 4, 5],
]);

$collection->union(); // [1, 2, 3, 4, 5]
```

diff
----

[](#diff)

```
public function diff()
```

Realiza a diferença entre todos os conjuntos da coleção

```
use Astronphp\Collection\Collection;

$collection = new Collection([
   [1, 2, 3],
   [3, 4, 5],
]);

$collection->diff(); // [1, 2]

$collection = new Collection([
   [3, 4, 5],
   [1, 2, 3],
]);
```

outer
-----

[](#outer)

```
public function outer()
```

Realiza a diferença total entre conjuntos

```
use Astronphp\Collection\Collection;

$collection = new Collection([
   [1, 2, 3],
   [3, 4, 5],
]);

$collection->outer(); // [[1, 2], [4, 5]]
```

intersect
---------

[](#intersect)

```
public function intersect()
```

Realiza a intersecção entre todos os conjuntos da coleção

```
use Astronphp\Collection\Collection;

$collection = new Collection([
   [1, 2, 3, 4],
   [3, 4, 5, 6],
]);

$collection->intersect(); // [3, 4]
```

cartesian
---------

[](#cartesian)

```
public function cartesian()
```

Realiza o produto cartesiano entre todos os conjuntos da coleção

```
use Astronphp\Collection\Collection;

$collection = new Collection([
   [1, 2, 3],
   [3, 4, 5],
]);

$collection->cartesian(); // [[1,3], [1,4], [1,5], [2,3], [2,4], [2,5], [3,3], [3,4], [3,5]]
```

isCollection
------------

[](#iscollection)

```
public static function isCollection(): bool
```

```
use Astronphp\Collection\Collection;

Collection::isCollection(new Collection()); // true

Collection::isCollection(10); // false
```

combine
-------

[](#combine)

```
public function combine(): self
```

```
use Astronphp\Collection\Collection;

$array = ['lorem', 'ipsum', 'dolor'];

$collection = new Collection([1, 2, 3]);

var_dump(Collection::combine($array, $collection));

/*
object(Astronphp\Collection\Collection)[2]
  protected 'content' =>
    array (size=3)
      'lorem' => int 1
      'ipsum' => int 2
      'dolor' => int 3
  protected 'length' => int 3
*/
```

range
-----

[](#range)

```
public static function range($start, $end, $step = 1): self
```

```
use Astronphp\Collection\Collection;

Collection::range($start = 10, $end = 20, $step = 2); // [10, 12, 14, 16, 18, 20]

Collection::range($start = 'A', $end = 'F'); // ["A", "B", "C", "D", "E", "F"]
```

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

1156d ago

Major Versions

v0.0.1 → v2.2.02023-05-04

### Community

Maintainers

![](https://www.gravatar.com/avatar/889890f3ed04be33fc2f778ef8fba7cb620183d1046b348be7c45ca1c9429188?d=identicon)[astronphp](/maintainers/astronphp)

---

Top Contributors

[![dezworkastronphp](https://avatars.githubusercontent.com/u/132532601?v=4)](https://github.com/dezworkastronphp "dezworkastronphp (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dezworkastronphp-collection/health.svg)

```
[![Health](https://phpackages.com/badges/dezworkastronphp-collection/health.svg)](https://phpackages.com/packages/dezworkastronphp-collection)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
