PHP code example of florianeckerstorfer / get-from

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

    

florianeckerstorfer / get-from example snippets


$baz = (isset($data->foo->bar->baz)) ? $data->foo->bar->baz : null;

$baz = florianec\get_from($data, ['foo', 'bar', 'baz']);

$data = new \stdClass();
$data->foo = new \stdClass();
$data->foo->bar = new \stdClass();
$data->foo->bar->baz = 'oof';

$name = florianec\get_from($data, ['foo', 'bar', 'baz']);
//= 'oof'

$data = new \stdClass();
$data->foo = 'bar';

$baz = florianec\get_from($data, ['baz']);
//= null

$data = new \stdClass();
$data->foo = 'bar';

$baz = florianec\get_from($data, ['baz'], 'qux');
//= 'qux'