bentools / set
The Set object lets you store unique values of any type, like in Javascript.
Installs: 8 007
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.4
Requires (Dev)
- pestphp/pest: ^1.22
- phpstan/phpstan: ^1.8
- squizlabs/php_codesniffer: ^3.7
- symfony/var-dumper: @stable
README
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.