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: 2022-02-01 12:56:19 UTC




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.


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"


# 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->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->all(); // ['bar', 'foo', 'fizz', 'baz']

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


$ composer test


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



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