PHP code example of torunar / array-functions

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

    

torunar / array-functions example snippets





$data_from_api = [
    [
        'currency' => [
            'code' => 'EUR',
        ],
        'amount' => [
            'value' => 42.00,
        ],
    ],
    [
        'currency' => [
            'code' => 'USD',
        ],
        'amount' => [
            'value' => 53.00,
        ],
    ],
    [
        'currency' => [
            'code' => 'JPY',
        ],
        'amount' => [
            'value' => 5300,
        ],
    ],
];

$necessary_data = \Torunar\array_column(
    $data_from_api,
    static function ($item, $key) {
        return $item['amount']['value'];
    },
    static function ($item, $key) {
        return $item['currency']['code'];
    }
);

var_dump(
    $necessary_data
);

array(3) {
  ["EUR"]=>
  float(42)
  ["USD"]=>
  float(53)
  ["JPY"]=>
  int(5300)
}