PHP code example of petrgrishin / array-map

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

    

petrgrishin / array-map example snippets


$array = ArrayMap::create($array)
    ->map(function ($value, $key) {
        return array($key => $value);
    })
    ->getArray();

$array = ArrayMap::create($array)
    ->map(function ($value) {
        return $value;
    })
    ->getArray();

$array = ArrayMap::create($array)
    ->mergeWith(array(
        1 => 1,
        2 => 2,
        3 => array(
            1 => 1,
            2 => 2,
        ),
    ))
    ->getArray();

$array = ArrayMap::create($array)
    ->mergeWith(array(
        1 => 1,
        2 => 2,
    ), false)
    ->getArray();

$array = ArrayMap::create($array)
    ->filter(function ($value, $key) {
        return $value > 10 && $key > 2;
    })
    ->getArray();

$array = ArrayMap::create($array)
    ->userSortByValue(function ($first, $second) {
        return $first < $second ? -1 : 1;
    })
    ->getArray();

$array = ArrayMap::create($array)
    ->userSortByKey(function ($first, $second) {
        return $first < $second ? -1 : 1;
    })
    ->getArray();