2017 © Pedro Peláez
 

library array-map-keys

Array map with keys

image

aviator/array-map-keys

Array map with keys

  • Saturday, November 25, 2017
  • by danielsdeboer
  • Repository
  • 1 Watchers
  • 0 Stars
  • 36 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 16 % Grown

The README.md

Latest Stable Version License Build Status, (*1)

Overview

PHP's array_map() function doesn't allow associative array key mutation. This package provides a function, array_map_keys(), which does., (*2)

The function iterates over an array and mutates each array item with the provided callback., (*3)

Installation

Via Composer:, (*4)

composer require aviator/array-map-keys

Testing

Via Composer:, (*5)

composer test

Usage

An array:, (*6)

$input = [
    [
        'company' => 'Aviator Creative',
        'owner' => 'Daniel Deboer',
        'email' => 'daniel.s.deboer@gmail.com',
    ],
    [
        'company' => 'Widget Makers',
        'owner' => 'Jane Doe',
        'email' => 'jane@widgets.com',
    ],
];

A callback:, (*7)

$callback = function ($key, $value) {
    return [
        $value['owner'] => $value['email'];
    ];
};

The array_map_keys function:, (*8)

$results = array_map_keys($input, $callback);

The output:, (*9)

echo $results;

/*
[
    'Daniel Deboer' => 'daniel.s.deboer@gmail.com',
    'Jane Doe' => 'jane@widgets.com',
]
*/

Other Stuff

License

This package is licensed with the MIT License (MIT)., (*10)

The Versions

25/11 2017

dev-master

9999999-dev https://github.com/danielsdeboer/array-map-keys

Array map with keys

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

php arrays php7 functional map

25/11 2017

0.1.0

0.1.0.0 https://github.com/danielsdeboer/array-map-keys

Array map with keys

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

php arrays php7 functional map