我從查詢中得到這個數組。如何將php數組索引設置爲數組值...?
Array
(
[0] => Array
(
[user_id] => 5
[first_name] => Diyaa
[profile_pic] => profile/user5.png
)
[1] => Array
(
[user_id] => 8
[first_name] => Raj
[profile_pic] => profile/user8.jpg
)
[2] => Array
(
[user_id] => 10
[first_name] => Vanathi
[profile_pic] => profile/user10.jpg
)
)
我需要設置數組索引像數組值(user_id
)如下面給出:
Array
(
[5] => Array
(
[user_id] => 5
[first_name] => Diyaa
[profile_pic] => profile/user5.png
)
[8] => Array
(
[user_id] => 8
[first_name] => Raj
[profile_pic] => profile/user8.jpg
)
[10] => Array
(
[user_id] => 10
[first_name] => Vanathi
[profile_pic] => profile/user10.jpg
)
)
注:user_id
是一個唯一的值,也不會重複再次。無需擔心索引值。
如何轉換並獲取該數組作爲指定的索引值..?
@ThisGuyHasTwoThumbs我想他想要什麼laravel調用['keyBy'](https://laravel.com/docs/5.4/collections#method-keyby) – apokryfos
@apokryfos啊我看到 - 刪除評論:) – ThisGuyHasTwoThumbs