PHP code example of timdev / php-array-utils

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

    

timdev / php-array-utils example snippets


use TimDev\ArrayUtils as A;

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

// $baz == 'baz'
$baz = A::val($array, ['foo', 'bar']);

// $nope == null
$nope = A::val($array, ['foo', 'bork']);

// $nope == 'squee'
$nope = A::val($array, ['i-do-not-exist'], 'squee');

// if you're just dereferencing by one level, you can pass int/string as second arg:
// $foo == ['bar' => 'baz']
$foo = A::val($array, 'foo');