2017 © Pedro Peláez
 

library array-path

image

peehaa/array-path

  • Monday, November 27, 2017
  • by PeeHaa
  • Repository
  • 1 Watchers
  • 1 Stars
  • 515 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

array-path

Code Coverage Build Status Scrutinizer Code Quality, (*1)

Yet another array path implementation, (*2)

Requirements

  • PHP 7.1+

Usage

get()

echo (new \PeeHaa\ArrayPath\ArrayPath())->get(['foo' => ['bar' => 'baz']], 'foo.bar'); // baz

echo (new \PeeHaa\ArrayPath\ArrayPath())->get(['foo' => ['bar' => 'baz']], 'foo.qux'); // throws \PeeHaa\ArrayPath\NotFoundException

exists()

echo (new \PeeHaa\ArrayPath\ArrayPath())->exists(['foo' => ['bar' => 'baz']], 'foo.bar'); // true

echo (new \PeeHaa\ArrayPath\ArrayPath())->exists(['foo' => ['bar' => 'baz']], 'foo.qux'); // false

set()

$array = [];

(new \PeeHaa\ArrayPath\ArrayPath())->set($array, 'foo.bar', 'value');

var_dump($array);
/**
array(1) {
  ["foo"]=>
  array(1) {
    ["bar"]=>
    string(5) "value"
  }
}
*/

remove()

    $array = ['foo' => ['bar' => 'value']];

    (new \PeeHaa\ArrayPath\ArrayPath())->remove($array, 'foo.bar');

    var_dump($array);
/**
array(1) {
  ["foo"]=>
  array(0) {
  }
}
*/

Note: remove() will not throw when the key does not exist in the array., (*3)

The Versions

27/11 2017

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

array utility path

31/10 2017

v1.0.0

1.0.0.0

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

array utility path