The Set object lets you store unique values of any type, like in Javascript.

1.1 2023-11-21 13:06 UTC

This package is auto-updated.

Last update: 2024-10-21 15:01:41 UTC


README

Latest Stable Version License CI Workflow Coverage Total Downloads

bentools/set

Javascript has a convenient way of deduplicating arrays:

const items = ['foo', 'bar', 'foo', 'baz'];
console.log([...new Set(items)]); // ['foo', 'bar', 'baz']

So why not PHP?

use Bentools\Set\Set;

$items = ['foo', 'bar', 'foo', 'baz'];
var_dump([...new Set($items)]); // ['foo', 'bar', 'baz']

Shorthand:

use function Bentools\Set\set;

$items = ['foo', 'bar', 'foo', 'baz'];
var_dump([...set($items)]); // ['foo', 'bar', 'baz']

Installation

composer require bentools/set

Tests

composer test

License

MIT.