PHP code example of shudrum / array-finder

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

    

shudrum / array-finder example snippets


use Shudrum\Component\ArrayFinder\ArrayFinder;

$arrayFinder = new ArrayFinder([
    'level_1' => [
        'level_2' => [
            'level_3' => 'value',
        ],
    ],
]);

$myValue = $arrayFinder->get('level_1.level_2.level_3');
// OR
$myValue = $arrayFinder['level_1.level_2.level_3'];

use Shudrum\Component\ArrayFinder\ArrayFinder;

$arrayFinder = new ArrayFinder([
    'a' => [
        'b' => [
            'c' => 'value1',
        ],
        'value2',
    ],
    'value3',
]);

$myValue = $arrayFinder->get('a.b.c'); // value1
$myValue = $arrayFinder->get('a.0'); // value2
$myValue = $arrayFinder->get(0); // value3

use Shudrum\Component\ArrayFinder\ArrayFinder;

$arrayFinder = new ArrayFinder();
$arrayFinder->set('a.b', 'value');

$arrayFinder->get(); // ['a' => ['b' => 'value]]

use Shudrum\Component\ArrayFinder\ArrayFinder;

$arrayFinder = new ArrayFinder([…]);

$myValue = $arrayFinder->changeSeparator('/');
$myValue = $arrayFinder->get('a/b/c');

use Shudrum\Component\ArrayFinder\ArrayFinder;

$arrayFinder = new ArrayFinder([…]);

$value = $arrayFinder['a.b'];
$arrayFinder['a.b.c'] = 'value';
unset($arrayFinder['a.b']);

use Shudrum\Component\ArrayFinder\ArrayFinder;

$arrayFinder = new ArrayFinder([…]);

count($arrayFinder);
count($arrayFinder['a.b']);

use Shudrum\Component\ArrayFinder\ArrayFinder;

$arrayFinder = new ArrayFinder([…]);

foreach ($arrayFinder as $key => $value) {
    // …
}