Search
 
SCRIPT & CODE EXAMPLE
 

PHP

change key value laravel map collection

// Using mapWithKeys
$collection = collect([
    [
        'name' => 'John',
        'department' => 'Sales',
        'email' => 'john@example.com',
    ],
    [
        'name' => 'Jane',
        'department' => 'Marketing',
        'email' => 'jane@example.com',
    ]
]);
 
$keyed = $collection->mapWithKeys(function ($item, $key) {
    return [$item['email'] => $item['name']];
});
 
$keyed->all();
 
/*
    [
        'john@example.com' => 'John',
        'jane@example.com' => 'Jane',
    ]
*/
Comment

PREVIOUS NEXT
Code Example
Php :: php catch all exceptions 
Php :: foreach in php 
Php :: laravel collection slice 
Php :: laravel redirect url 
Php :: how to use a session in blade 
Php :: index.php wont load as main 
Php :: redirect compact laravel 
Php :: for loop in laravel 
Php :: migrate specific migration file laravel 
Php :: php json_encode utf8 
Php :: PDOException::("could not find driver") windows 
Php :: laravel slug 
Php :: laravel observer check if field changed 
Php :: PHP Forms - Required Fields 
Php :: laravel handle queryexception 
Php :: Create a laravel project with any version 
Php :: laravel chunk select 
Php :: php cheatsheet 
Php :: get array length using php 
Php :: upload_max_filesize in wordpress 
Php :: php credit card validation 
Php :: show php all errors 
Php :: hello world in php 
Php :: laravel tree category 
Php :: laravel use function from another controller 
Php :: laravel checking if a record exists 
Php :: htmlspecialchars_decode (PHP 5 = 5.1.0, PHP 7, PHP 8) htmlspecialchars_decode — Convert special HTML entities back to characters 
Php :: php implode keys 
Php :: php strtotime plus 1 day 
Php :: number format without comma php 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =