PHP code example of chipslays / array

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

    

chipslays / array example snippets

 
use Chipslays\Arr\Arr;

$array = [
    'user' => [
        'name' => 'chipslays'
    ],
];

$name = Arr::get($array, 'user.name'); // chipslays
$email = Arr::get($array, 'user.email', '[email protected]'); // [email protected] 

$array = [
    'foo' => [
        'bar' => ['baz' => 1],
        'bam' => ['baz' => 2],
        'boo' => ['baz' => 3],
    ],
];

$results = arr_get($array, 'foo.*.baz');

// Array
// (
//     [0] => 1
//     [1] => 2
//     [2] => 3
// )

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

$results = arr_get($array, 'foo.*.baz');

// 1

$array = [
    'foo' => [
        'bar' => ['baz' => 1],
        'bam' => ['baz' => 2],
        'boo' => ['baz' => 3],
    ],
];

$results = arr_get($array, 'foo.*');

// Array
// (
//     [0] => Array
//         (
//             [baz] => 1
//         )
//     [1] => Array
//         (
//             [baz] => 2
//         )
//     [2] => Array
//         (
//             [baz] => 3
//         )
// )

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

$results = arr_get($array, 'foo.*');

// Array
// (
//     [baz] => 1
// )
 
use Chipslays\Arr\Arr;

$array = [
    'user' => [
        'name' => 'chipslays'
    ],
];

Arr::set($array, 'user.name', 'john doe'); 
Arr::set($array, 'user.email', '[email protected]'); 

Array
(
    [user] => Array
        (
            [name] => john doe
            [email] => [email protected]
        )

)

use Chipslays\Arr\Arr;

$array = [
    'user' => [
        'name' => 'chipslays',
        'string' => '',
        'null' => null,
        'false' => false,
    ],
];

Arr::has($array, 'user.name'); // true
Arr::has($array, 'user.string'); // true
Arr::has($array, 'user.null'); // true
Arr::has($array, 'user.false'); // true
Arr::has($array, 'user.empty_value'); // false

use Chipslays\Arr\Arr;

$array = [
    'user' => [
        'name' => 'chipslays',
        'string' => '',
        'null' => null,
        'false' => false,
    ],
];

// todo