svem/heap

此包已被废弃且不再维护。未建议替代包。

更易于处理PHP中的数组。集合 '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


README

heap

Heap

Latest Version on Packagist Software License Build Status Total Downloads

Heap是处理PHP中数组的一种便捷方式。此包提供了易于理解的API,并且从PHP内置的混乱数组函数中解脱出来。

安装

通过composer安装此包

$ composer require sven/heap

或者,将包添加到你的composer.json文件中的依赖项,并运行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->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(); // []

测试

$ composer test

安全

如果你发现任何安全相关的问题,请通过电子邮件svenluijten@outlook.com联系,而不是使用问题跟踪器。

致谢

许可证

MIT许可证(MIT)。请参阅许可证文件以获取更多信息。