PHP code example of jdrieghe / array-helpers

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

    

jdrieghe / array-helpers example snippets


use function ArrayHelpers\array_get;

$result = array_get($array, $key, $default);

$data = [
    'foo' => [
        'bar' => 'baz',
    ],
];

Arr::get($data, 'foo');
// returns: ['bar' => 'baz'];
 
Arr::get($data, 'foo.bar'); 
// returns: 'baz';

Arr::get($data, 'xyz', 'default');
// returns: 'default';

$data = [
    'foo' => [
        'bar' => 'baz',
    ],
];

Arr::has($data, 'foo');
// returns: true;
 
Arr::has($data, 'foo.bar'); 
// returns: true;

Arr::has($data, 'xyz');
// returns: false;

$data = [];
Arr::set($data, 'foo.bar', 'baz');