PHP code example of seffeng / arr-helper

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

    

seffeng / arr-helper example snippets


/**
 * TestController.php
 * 示例
 */
namespace App\Http\Controllers;

use Seffeng\ArrHelper\Arr;
use Seffeng\ArrHelper\ReplaceArrayValue;

class TestController extends Controller
{
    public function index()
    {
        $arr = [
            'a' => [
                'b' => [
                    'c' => 'ccc'
                ]
            ],
            'd' => [
                'b' => 'ccc',
                'e' => [
                    'f' => 'hhh'
                ]
            ]
        ];
        echo '<pre>';
        var_dump(Arr::getValue($arr, 'a.b.c', ''));
        var_dump(Arr::getDepth($arr));
        print_r(Arr::getColumn($arr, 'b'));
        print_r($arr);
        print_r(Arr::merge($arr, [
            'd' => new ReplaceArrayValue(['hhh' => 'iii']),
            'i' => [
                'j' => 'kkk'
            ]
        ]));
    }
}

|---src
|   |   Arr.php
|   |   ReplaceArrayValue.php
|   |   UnsetArrayValue.php
|   |---Traits
|           ArrTrait.php
|---tests
|       ArrTest.php