PHP code example of dennobaby / pathfinder

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

    

dennobaby / pathfinder example snippets




use Denno\PathFinder\PathFinder;

$array = [
    'some' => [
        'multi' => [
            'dimensional' => [
                'array' => 'foo',
            ],
        ],
    ],
];

echo PathFinder::getPathValue($array, 'some.multi.dimensional.array');
echo PathFinder::getPathValue($array, 'some.multi.nonexisting.key');

echo PathFinder::setPathValue($array, 'some.multi.dimensional.array', 'bar');
//would return 'bar'
//let's check it:
echo PathFinder::getPathValue($array, 'some.multi.dimensional.array');
//would return true.

//but a nonexisting path? 
echo PathFinder::setPathValue($array, 'some.multi.nonexisting.key', 'foobar');
//would return false, because the path don't exist!

//but you want it to be created and the value set? No problem:
echo PathFinder::setPathValue($array, 'some.multi.nonexisting.key', 'foobar', true);
//the last parameter, named 'force', will create it for you if set to true and therefor return 'foobar'