PHP code example of peehaa / array-path

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

    

peehaa / array-path example snippets


echo (new \PeeHaa\ArrayPath\ArrayPath())->get(['foo' => ['bar' => 'baz']], 'foo.bar'); // baz
    
echo (new \PeeHaa\ArrayPath\ArrayPath())->get(['foo' => ['bar' => 'baz']], 'foo.qux'); // throws \PeeHaa\ArrayPath\NotFoundException

echo (new \PeeHaa\ArrayPath\ArrayPath())->exists(['foo' => ['bar' => 'baz']], 'foo.bar'); // true
    
echo (new \PeeHaa\ArrayPath\ArrayPath())->exists(['foo' => ['bar' => 'baz']], 'foo.qux'); // false

$array = [];

(new \PeeHaa\ArrayPath\ArrayPath())->set($array, 'foo.bar', 'value');
    
var_dump($array);

    $array = ['foo' => ['bar' => 'value']];

    (new \PeeHaa\ArrayPath\ArrayPath())->remove($array, 'foo.bar');
    
    var_dump($array);