PHP code example of saasformation / array-by-path

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

    

saasformation / array-by-path example snippets


$array = [
    'data' => [
        'id' => '53b3ed90-b5ae-11ec-b909-0242ac120002',
        'attributes' => [
            'name' => 'John',
            'surname' => 'Smith',
            'birthdate' => '1990-01-20',
            'savings_total_amount' => [
                'amount' => 2045033,
                'currency' => 'EUR'
            ]
        ]
    ]
];

$name = (new RetrieveArrayValueByPathService())->find('data.attributes.name', $array); // "John"

$invalidPath = (new RetrieveArrayValueByPathService())->find('foo', $array); // null

$invalidPath = (new RetrieveArrayValueByPathService())->get('foo', $array); // InvalidPathException

(new SetValueToArrayByPathService())->insert('data.attributes.height', $array, 177);