2017 © Pedro Peláez
 

library dotted

php library to access multidimensional arrays

image

fnayou/dotted

php library to access multidimensional arrays

  • Monday, August 14, 2017
  • by fnayou
  • Repository
  • 1 Watchers
  • 3 Stars
  • 248 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 85 % Grown

The README.md

Dotted

, (*1)

Scrutinizer Code Quality Build Status SensioLabsInsight Version Build Status, (*2)

Dotted is a PHP library to manage multidimensional arrays !, (*3)

It will help you checking, accessing or inserting values of an array., (*4)

Installation

use Composer to install dotted library :, (*5)

$ php composer.phar require fnayou/dotted

or download the latest release and include src/Dotted.php in your project., (*6)

Usage

first, you create dotted object by passing the array content., (*7)

next you can check, access or insert values with ease., (*8)

<?php

    use Fnayou\Dotted;

    $content = [
        'keyOne' => 'valueOne',
        'keyTwo' => [
            'keyThree' => 3, 
            'keyFour' => false,
            'keyFive' => [
                true,
                'valueFive',
                5,
            ]
        ]
    ];

    $dotted = new Dotted($content);
    // or
    $dotted = Dotted::create($content);

    // check if values exist
    echo $dotted->has('keyOne');                        // output : true
    echo $dotted->has('keyTwo.keySix');                 // output : false

    // access values
    echo $dotted->get('keyOne');                        // output : valueOne
    echo $dotted->get('keyTwo.keyThree');               // output : 3
    echo $dotted->get('keyTwo.keyFive.0');              // output : true

    // access non-existent value
    echo $dotted->get('keyTwo.keySix');                 // output : null

    // access value with default value 
    echo $dotted->get('keyTwo.keySix', 'defaultValue'); // output : defaultValue

    // insert value
    $dotted->set('keyTwo.keySix', 'valueSix');
    echo $dotted->get('keyTwo.keySix');                 // output : valueSix

    // insert value with override
    $dotted->set('keyTwo.keySix', 6);                   // output : 6

    // access values (array content) 
    $dotted->getValues();
    /** output : 
      array:2 [▼
        "keyOne" => "valueOne"
        "keyTwo" => array:3 [▼
          "keyThree" => 3
          "keyFour" => false
          "keyFive" => array:3 [▼
            0 => true
            1 => "valueFive"
            2 => 5
          ]
        ]
      ]
    */

    // access flatten values
    $dotted->flatten();
    /** output :
      array:6 [▼
        "keyOne" => "valueOne"
        "keyTwo.keyThree" => 3
        "keyTwo.keyFour" => false
        "keyTwo.keyFive.0" => true
        "keyTwo.keyFive.1" => "valueFive"
        "keyTwo.keyFive.2" => 5
      ]
    */

Credits

Aymen FNAYOU, (*9)

License

license Please see License File for more information., (*10)

The Versions

14/08 2017

dev-master

9999999-dev https://github.com/fnayou/dotted

php library to access multidimensional arrays

  Sources   Download

MIT

The Development Requires

php array notation multidimensional dotted

14/08 2017
14/08 2017

dev-docker

dev-docker https://github.com/fnayou/dotted

php library to access multidimensional arrays

  Sources   Download

MIT

The Development Requires

php array notation multidimensional dotted

20/06 2017