jeudi 7 septembre 2017

Laravel Collection. Map one keys to other

I want to map some keys in Laravel collection to other, that are stored in an array.

I can't "invent" a proper neat and short pipeline for such a transformation.

Here is a simplified example of what I want:

$mappedKeys = [
    1 => 'One',
    2 => 'Two',
    3 => 'Three',
];

$data = collect([
    1 => 'I',
    2 => 'II',
    3 => 'III',
]);

$resultCollection = $data->...

/*
 * I want to receive after some manipulations
 *
 * [
 *      'One'   => 'I',
 *      'Two'   => 'II',
 *      'Three' => 'II',
 * ]
 */



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire