Answers for "laravel map array"

PHP
0

none

// The array we're going to return
    $data = 
Posted by: Guest on January-01-1970
0

laravel map array

collect($deliver_addresses)->map(function ($address) use ($input) {

    $address['id']              = $input['id'];
    $address['a_new_attribute'] = $input['a_new_attribute'];

    return $address;

});
Posted by: Guest on September-27-2021
0

laravel mapWithKeys

$collection = collect([
    [
        'name' => 'John',
        'department' => 'Sales',
        'email' => '[email protected]',
    ],
    [
        'name' => 'Jane',
        'department' => 'Marketing',
        'email' => '[email protected]',
    ]
]);

$keyed = $collection->mapWithKeys(function ($item) {
    return [$item['email'] => $item['name']];
});

$keyed->all();

/*
    [
        '[email protected]' => 'John',
        '[email protected]' => 'Jane',
    ]
*/
Posted by: Guest on February-08-2021

Browse Popular Code Answers by Language