PHP code example of dschoenbauer / dot-notation

1. Go to this page and download the library: Download dschoenbauer/dot-notation 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/ */

    

dschoenbauer / dot-notation example snippets


use DSchoenbauer\DotNotation\ArrayDotNotation;

$mongoConnection = [ 
    'mongo' => [ 
        'default' => [  'user' => 'username', 'password' => 's3cr3t' ]
    ]
];
$config = new ArrayDotNotation($mongoConnection);
        --- or ---
$config = ArrayDotNotation::with($mongoConnection);

// Get plain value
$user = $config->get('mongo.default.user');
/*
    $user = 'username';
*/ 

// Get array value
$mongoDefault = $config->get('mongo.default'); 
/* 
    $mongoDefault = ['user' => 'username', 'password' => 's3cr3t'];
*/
`
$configDump = $config->set('mongo.numbers', [2, 3, 5, 7, 11])->getData();
/*
    $configDump = [
        'mongo' => [
            'default' => [  'user' => 'username', 'password' => 's3cr3t' ],
            'numbers' => [2, 3, 5, 7, 11]
        ],
        'title' => 'Dot Notation'
    ];
*/
`
$configDump = $config->merge('mongo.default', ['user' => 'otherUser','active' => true])->getData();
/*
    $configDump = [
        'mongo' => [
           'default' => [  'user' => 'otherUser', 'password' => 's3cr3t','active' => true ]
        ],
        'title' => 'Dot Notation'
    ];
*/