我从查询中得到这个数组。如何将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