Simplify list to associative array conversion #148

This commit is contained in:
Nabeel Shahzad 2018-01-21 13:59:51 -05:00
parent 33cbceaa92
commit 3c78b5f1e2

View File

@ -37,13 +37,16 @@ if(!function_exists('list_to_assoc')) {
* ['item1' => 'item1', 'item2' => 'item2']
*
* @param array $list
* @return \Illuminate\Support\Collection
* @return array
*/
function list_to_assoc(array $list)
{
return collect($list)->mapWithKeys(function ($item) {
return [$item => $item];
});
$ret = [];
foreach($list as $item) {
$ret[$item] = $item;
}
return $ret;
}
}