PHP code example of krak / array

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

    

krak / array example snippets




use Krak\Arr;

$data = [
    'a' => [
        'b' => 1,
    ],
];

$res = Arr\get($data, 'a.b');
assert($res == 1);

Arr\set($data, 'c.d', 2);
assert($data['c']['d'] == 2);

// or use the global aliases
array_get($data, 'a.b');



use Krak\Arr;

$bag = new Arr\Bag();
$bag->set('a.b', 1);
var_dump($bag->raw());
/*
    array(1) {
      ["a"]=>
      array(1) {
        ["b"]=>
        int(1)
      }
    }
*/



namespace Krak\Arr;

class Bag implements ArrayAccess {
    public function __construct(array $data = [])
    public function get($key, $else = null, $sep = '.')
    public function getIn(array $key, $else = null)
    public function set($key, $value, $sep = '.')
    public function has($key, $sep = '.')
    public function hasIn(array $key)
    public function del($key, $sep = '.')
    public function raw()
}