sven/heap

This package is abandoned and no longer maintained. No replacement package was suggested.

Easier handling for arrays in PHP. Collections 'lite'.

0.0.2 2016-03-10 10:59 UTC

This package is not auto-updated.

Last update: 2019-02-20 18:52:39 UTC


README

heap

Heap

Latest Version on Packagist Software License Build Status Total Downloads

Heap is a handy way of interacting with arrays in PHP. This package provides you with an easy to understand API and a much needed break from the mess that is PHP's built-in array functions.

Installation

Install this package via composer:

$ composer require sven/heap

Alternatively, add the package to your dependencies in your composer.json file and run composer update:

{
    "require": {
        "sven/heap": "0.0.2"
    }
}

Usage

# New up an instance of the class.
$heap = new Sven\Heap\Heap;

# You can also pass in an array to push to the heap.
$heap = new Sven\Heap\Heap(['foo', 'bar', 'baz']);
# Push an item into the heap.
$heap->push('foo');
$heap->all(); // ['foo']
# Merge an existing array into the heap.
$heap->merge(['fizz', 'baz']);
$heap->all(); // ['foo', 'fizz', 'baz']
# Get the first or last item from the heap.
$heap->first(); // 'foo'
$heap->last(); // 'baz'

# Get the first or last `n` items from the heap.
$heap->first(2); // ['foo', 'fizz']
$heap->last(2); // ['fizz', 'baz']
# Pre- or append an item to the heap.
$heap->prepend('bar');
$heap->all(); // ['bar', 'foo', 'fizz', 'baz']

$heap->append('buzz');
$heap->all(); // ['bar', 'foo', 'fizz', 'baz', 'buzz']
$heap->random(); // 'baz' (retrieved randomly)
# Empty the entire array.
$heap->nuke();
$heap->all(); // []

Testing

$ composer test

Security

If you discover any security related issues, please email svenluijten@outlook.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.