PHP code example of agrandesr / arrays

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

    

agrandesr / arrays example snippets




use Agrandesr\Utils\Arrays;

$array=['lvl1'=>['lvl2'=>'lvl3'=>'content'];

$data = Arrays::pathGet('lvl1.lvl2.lvl3',$array);

echo $data;
 php
$test=[];
echo json_encode(Arrays::pathSet('lvl1.lvl2.lvl3','test',$test));
//Output: {'lvl1':{'lvl2':{'lvl3':'test'}}}
 php
$test=[
    'lvl1'=>[
        'lvl2'=>''
    ],
    '1lvl'=>[
        '2lvl'=>[1,2,3]
    ]
];
echo json_encode(Arrays::pathSet('lvl1.lvl2.lvl3','test',$test));
/*
//Output:
{
    "lvl1":{
        "lvl2":{
            "lvl3":"test"
        }
    },
    "1lvl":{
        "2lvl":[1,2,3]
    }
}
*/
 php
$test=[
    'lvl1'=>[
        'lvl2'=>''
    ],
    '1lvl'=>[
        '2lvl'=>[1,2,3]
    ]
];
echo Arrays::pathGet('1lvl.2lvl.1',$test);
//Output: 2
 php
$test=[
    'lvl1'=>[
        'lvl2'=>''
    ],
    '1lvl'=>[
        '2lvl'=>[1,2,3]
    ]
];
echo Arrays::pathGet('1lvl.2lvl.1',$test);
//Output: 2