Giter Club home page Giter Club logo

dotted's Introduction

Dotted

Scrutinizer Code Quality Build Status SensioLabsInsight Version

Dotted is a PHP library to manage multidimensional arrays !

It will help you checking, accessing or inserting values of an array.

Installation

use Composer to install dotted library :

$ php composer.phar require fnayou/dotted

or download the latest release and include src/Dotted.php in your project.

Usage

first, you create dotted object by passing the array content.

next you can check, access or insert values with ease.

<?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

License

license Please see License File for more information.

dotted's People

Contributors

fnayou avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.