PHP code example of fnayou / dotted

1. Go to this page and download the library: Download fnayou/dotted library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fnayou / dotted example snippets




    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
      ]
    */
shell
$ php composer.phar