2017 © Pedro Peláez
 

library array

A collection of missing php array functions

image

krak/array

A collection of missing php array functions

  • Tuesday, December 19, 2017
  • by ragboyjr
  • Repository
  • 1 Watchers
  • 1 Stars
  • 2,654 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 23 % Grown

The README.md

Array

The array library is just a simple collection of missing php array functions., (*1)

Installation

Install with composer at krak/array, (*2)

Usage

<?php

use Krak\Arr;

$data = [
    'a' => [
        'b' => 1,
    ],
];

$res = Arr\get($data, 'a.b');
assert($res == 1);

Arr\set($data, 'c.d', 2);
assert($data['c']['d'] == 2);

// or use the global aliases
array_get($data, 'a.b');

There also is a Bag class which provides an object oriented API for the arrays., (*3)

<?php

use Krak\Arr;

$bag = new Arr\Bag();
$bag->set('a.b', 1);
var_dump($bag->raw());
/*
    array(1) {
      ["a"]=>
      array(1) {
        ["b"]=>
        int(1)
      }
    }
*/

API

The following are defined in the namespace Krak\Arr:, (*4)

array expand(iterable $iterable, string $separator = '.')
array index_by(iterable $iterable, string $key)
array udiff_stable(iterable $a, iterable $b, callable $cmp)
mixed get(array $data, string $key, mixed $else = null)
mixed getIn(array $data, array $key, mixed $else = null);
bool has(array $data, string $key, string $sep = '.')
bool hasIn(array $data, array $key)
void set(array &$data, string $key, mixed $value, string $sep = '.')
void del(array &$data, string $key, string $sep = '.')

You can also use the globally defined aliases, (*5)

array_expand
array_index_by
array_udiff_stable
array_get
array_has
array_set
array_del

Or the Krak\Arr\Bag class:, (*6)

<?php

namespace Krak\Arr;

class Bag implements ArrayAccess {
    public function __construct(array $data = [])
    public function get($key, $else = null, $sep = '.')
    public function getIn(array $key, $else = null)
    public function set($key, $value, $sep = '.')
    public function has($key, $sep = '.')
    public function hasIn(array $key)
    public function del($key, $sep = '.')
    public function raw()
}

Tests

Run tests with phpunit, (*7)

The Versions

19/12 2017

dev-master

9999999-dev https://github.com/krakphp/array

A collection of missing php array functions

  Sources   Download

MIT

The Requires

  • php >=5.2

 

The Development Requires

php array misc

19/12 2017

v0.4.3

0.4.3.0 https://github.com/krakphp/array

A collection of missing php array functions

  Sources   Download

MIT

The Requires

  • php >=5.2

 

The Development Requires

php array misc

13/04 2017

v0.4.2

0.4.2.0 https://github.com/krakphp/array

A collection of missing php array functions

  Sources   Download

MIT

The Requires

  • php >=5.2

 

The Development Requires

php array misc

04/04 2017

v0.4.1

0.4.1.0 https://github.com/krakphp/array

A collection of missing php array functions

  Sources   Download

MIT

The Requires

  • php >=5.2

 

The Development Requires

php array misc

07/01 2017

v0.4.0

0.4.0.0 https://github.com/krakphp/array

A collection of missing php array functions

  Sources   Download

MIT

The Requires

  • php >=5.2

 

The Development Requires

php array misc

05/08 2015

v0.3.0

0.3.0.0 http://gitlab.bighead.net/krak/array

A collection of missing php array functions

  Sources   Download

MIT

The Requires

  • php >=5.2

 

The Development Requires

php array misc

07/05 2015

v0.2.0

0.2.0.0 http://gitlab.bighead.net/bighead/krak-array

A collection of missing php array functions

  Sources   Download

MIT

The Requires

  • php >=5.2

 

The Development Requires

php array misc

07/05 2015

v0.1.0

0.1.0.0 http://gitlab.bighead.net/bighead/krak-array

A collection of missing php array functions

  Sources   Download

MIT

php array misc