【发布时间】:2020-09-05 16:52:01
【问题描述】:
Array
(
[0] => stdClass Object
(
[category_id] => 5
[distributor_id] => 999999
[name] => Attractions
[parent_category_id] => 0
[is_global_category] => 0
[category_logo] => qrcodes/categoryupload/img_1438954822_attractions.png
[is_active] => 1
[ticket_ids] =>
[position] => 0
)
[1] => stdClass Object
(
[category_id] => 5
[distributor_id] => 8885
[name] => Attractions
[parent_category_id] => 0
[is_global_category] => 0
[category_logo] => qrcodes/categoryupload/img_1438954822_attractions.png
[is_active] => 1
[ticket_ids] =>
[position] => 0
)
[2] => stdClass Object
(
[category_id] => 6
[distributor_id] => 999999
[name] => Walk & Bike
[parent_category_id] => 0
[is_global_category] => 0
[category_logo] => qrcodes/categoryupload/img_1438406863_walk-bike.png
[is_active] => 1
[ticket_ids] => ["13594"]
[position] => 0
)
)
我想从这个数组中创建一个新数组。这里有两种类型的分销商 id 可以是:
[distributor_id] => 999999 这是固定的
秒是
[distributor_id] => $cod_id(8885) 任何登录的人
现在我想创建新数组并希望优先考虑 [distributor_id] => $cod_id(8885) 并希望结果看起来像这样
Array
(
[0] => stdClass Object
(
[category_id] => 5
[distributor_id] => 8885
[name] => Attractions
[parent_category_id] => 0
[is_global_category] => 0
[category_logo] => qrcodes/categoryupload/img_1438954822_attractions.png
[is_active] => 1
[ticket_ids] =>
[position] => 0
)
[1] => stdClass Object
(
[category_id] => 6
[distributor_id] => 999999
[name] => Walk & Bike
[parent_category_id] => 0
[is_global_category] => 0
[category_logo] => qrcodes/categoryupload/img_1438406863_walk-bike.png
[is_active] => 1
[ticket_ids] => ["13594"]
[position] => 0
)
)
如何使用 foreach 和其他解决方案来处理它
【问题讨论】:
-
这能回答你的问题吗? Sort array of objects by object fields
-
@Dum 满足不了我的要求
-
你试过什么?你被困在哪里了?
标签: php arrays codeigniter sorting laravel-5