PHPackages                             sven/heap - 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. sven/heap

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

sven/heap
=========

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

0.0.2(10y ago)112MITPHPPHP ^7.0

Since Mar 10Pushed 9y ago2 watchersCompare

[ Source](https://github.com/svenluijten/heap)[ Packagist](https://packagist.org/packages/sven/heap)[ RSS](/packages/sven-heap/feed)WikiDiscussions master Synced 2mo ago

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

[![heap](https://cloud.githubusercontent.com/assets/11269635/13665972/69637e6e-e6af-11e5-970e-dbbd1800978a.jpg)](https://cloud.githubusercontent.com/assets/11269635/13665972/69637e6e-e6af-11e5-970e-dbbd1800978a.jpg)

Heap
====

[](#heap)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b71358377ce59886ba032c835c45be0895eca6c6004d6a1af5fcde7215b83c7a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7376656e2f686561702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sven/heap)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/a78e2bdd0b3354d9d8d123add636839d2789c9128903fd338c1b66a22e504329/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7376656e6c75696a74656e2f686561702f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/svenluijten/heap)[![Total Downloads](https://camo.githubusercontent.com/66766839f36c8dad5f583ace113370c4df21835c2f714f8ff469479f9c877757/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7376656e2f686561702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sven/heap)

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
------------

[](#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
-----

[](#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
-------

[](#testing)

```
$ composer test
```

Security
--------

[](#security)

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

Credits
-------

[](#credits)

- [Sven Luijten](https://github.com/svenluijten)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity50

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

2

Last Release

3718d ago

PHP version history (2 changes)0.0.1PHP ^5.6 || ^7.0

0.0.2PHP ^7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/6682e025b83b7a93b4d43c5c9b0b2245d790d72352758c47b81ba14858f45a8a?d=identicon)[svenluijten](/maintainers/svenluijten)

---

Top Contributors

[![svenluijten](https://avatars.githubusercontent.com/u/11269635?v=4)](https://github.com/svenluijten "svenluijten (16 commits)")

---

Tags

arraycollectionheap

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sven-heap/health.svg)

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

###  Alternatives

[aimeos/map

Easy and elegant handling of PHP arrays as array-like collection objects similar to jQuery and Laravel Collections

4.2k412.9k11](/packages/aimeos-map)[athari/yalinqo

YaLinqo, a LINQ-to-objects library for PHP

4561.2M5](/packages/athari-yalinqo)[yansongda/supports

common components

211.4M31](/packages/yansongda-supports)[armincms/json

A Laravel Nova field.

25149.4k3](/packages/armincms-json)[graze/sort

A collection of array sorting transforms and functions

12289.6k2](/packages/graze-sort)[graze/data-structure

Data collections and containers

12287.4k8](/packages/graze-data-structure)

PHPackages © 2026

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