原始数据
Collection {#1643 ▼需要得到的数据
#items: array:10 [▼
1 => {#1677 ▼
+"id": 1
+"name": "测试"
}
2 => {#1673 ▼
+"id": 2
+"name": "格格寄存"
}
3 => {#1672 ▼
+"id": 3
+"name": "格格洗衣"
}
4 => {#1671 ▼
+"id": 4
+"name": "格格租借"
}
5 => {#1670 ▼
+"id": 5
+"name": "丰巢寄件"
}
6 => {#1669 ▼
+"id": 6
+"name": "裹裹寄件"
}
7 => {#1668 ▼
+"id": 7
+"name": "裹儿寄件"
}
8 => {#1667 ▼
+"id": 8
+"name": "格格快递员预定"
}
9 => {#1666 ▼
+"id": 9
+"name": "格格快递员租用"
}
10 => {#1665 ▼
+"id": 10
+"name": "圆通预约"
}
]}
array:10 [▼把二维数据转成一维数组
1 => "测试"
2 => "格格寄存"
3 => "格格洗衣"
4 => "格格租借"
5 => "丰巢寄件"
6 => "裹裹寄件"
7 => "裹儿寄件"
8 => "格格快递员预定"
9 => "格格快递员租用"
10 => "圆通预约"]
$new = collect($merchant_items)->reduce(function($res,$item){
return $res + [$item->id => $item->name];
},[]);
本文来自博客园,作者:孙龙-程序员,转载请注明原文链接:https://www.cnblogs.com/sunlong88/articles/8681534.html