2017 © Pedro Peláez
 

library dot

Simplified array dot notation for PHP

image

selvinortiz/dot

Simplified array dot notation for PHP

  • Thursday, July 7, 2016
  • by selvinortiz
  • Repository
  • 2 Watchers
  • 4 Stars
  • 91 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 2 % Grown

The README.md

Dot, (*1)

Build Status Total Downloads Latest Stable Version, (*2)

Description

Dot is a tiny library and implements array dot notation for PHP written by Selvin Ortiz, (*3)

Requirements

Install

composer require selvinortiz/dot

Test

sh spec.sh

Usage

To use Dot after proper installation, just autoload it, use it, and call methods on it:), (*4)

$input = [
    'name' => [
        'first' => 'Brad',
        'last'  => 'Bell',
    ],
    'spouse' => [
        'name' => [
            'first' => 'Brandon',
            'last'  => 'Kelly'
        ],
        'mood' => 'Happy',
        'age'  => '75',
    ],
    'mood' => 'Angry',
    'age'  => 25,
];

Dot::has($input, 'spouse');
// true

Dot::has($input, 'mistress.relationship');
// false

Dot::get($input, 'spouse.name.last');
// 'Kelly'

Dot::get($input, 'spouse');
/*
[
    'name' => [
        'first' => 'Brandon',
        'last'  => 'Kelly'
    ],
    'mood' => 'Happy',
    'age'  => '75'
]
*/

Dot::set($input, 'spouse.name.last', 'Bell');
/* $input will be mutated with a changed value
[
    'name' => [
        'first' => 'Brad',
        'last'  => 'Bell',
    ],
    'spouse' => [
        'name' => [
            'first' => 'Brandon',
            'last'  => 'Bell'
        ],
        'mood' => 'Happy',
        'age'  => '75',
    ],
    'mood' => 'Angry',
    'age'  => 25,
];
*/

Dot::delete($input, 'spouse.mood');
/* $input will be mutated with a key/value deleted
[
    'name' => [
        'first' => 'Brad',
        'last'  => 'Bell',
    ],
    'spouse' => [
        'name' => [
            'first' => 'Brandon',
            'last'  => 'Bell'
        ]
        'age'  => '75',
    ],
    'mood' => 'Angry',
    'age'  => 25,
];
*/

API

Dot has a very small API and hoping to keep it small and to the point., (*5)

Dot::has($arr, $key)

Returns whether or not $arr has $key. Put another way, $key exists in $arr, (*6)

Dot::get($arr, $key, $default = null)

Returns the value found in $arr by $key or $default provided, (*7)

Dot::set(array &$arr, $key, $value)

Mutates the $arr by adding a new $key with $value provided, (*8)

Dot::delete(array &$arr, $key)

Mutates the $arr by delete $key and its associated value if found, (*9)

Contribute

Dot wants to be friendly to first time contributors. Just follow the steps below and if you have questions along the way, please reach out., (*10)

  1. Fork it!
  2. Create your bugfix or feature branch
  3. Commit and push your changes
  4. Submit a pull request

License

Dot is open source software licensed under the MIT License, (*11)

The Versions

07/07 2016

dev-master

9999999-dev

Simplified array dot notation for PHP

  Sources   Download

MIT

The Requires

 

07/07 2016

dev-dev

dev-dev

Simplified array dot notation for PHP

  Sources   Download

MIT

The Requires

 

07/07 2016

v1.1.0

1.1.0.0

Simplified array dot notation for PHP

  Sources   Download

MIT

The Requires

 

25/06 2016

v1.0.0

1.0.0.0

Simplified array dot notation for PHP

  Sources   Download

MIT

The Requires