按列值对多维数组的每个子数组进行排序
我有以下数组,我想按 value
对子数组进行排序。
[
'bwin' => [
['bookie' => 'bwin', 'id_bookie' => 178537, 'value' => 6.00, 'bet' => 1],
['bookie' => 'bwin', 'id_bookie' => 178537, 'value' => 1.45, 'bet' => 2],
['bookie' => 'bwin', 'id_bookie' => 178537, 'value' => 4.50, 'bet' => 'x']
],
'NordicBet' => [
['bookie' => 'NordicBet', 'id_bookie' => 201581, 'value' => 5.75, 'bet' => 1],
['bookie' => 'NordicBet', 'id_bookie' => 201581, 'value' => 1.50, 'bet' => 2],
['bookie' => 'NordicBet', 'id_bookie' => 201581, 'value' => 4.30, 'bet' => 'x']
],
'Canbet' => [
['bookie' => 'Canbet', 'id_bookie' => 176582, 'value' => 5.60, 'bet' => 1],
['bookie' => 'Canbet', 'id_bookie' => 176582, 'value' => 1.56, 'bet' => 2],
['bookie' => 'Canbet', 'id_bookie' => 176582, 'value' => 3.80, 'bet' => 'x']
],
'Expekt' => [
['bookie' => 'Expekt', 'id_bookie' => 235615, 'value' => 5.60, 'bet' => 1],
['bookie' => 'Expekt', 'id_bookie' => 235615, 'value' => 1.50, 'bet' => 2],
['bookie' => 'Expekt', 'id_bookie' => 235615, 'value' => 4.25, 'bet' => 'x']
],
'StanJames' => [
['bookie' => 'StanJames', 'id_bookie' => 243649, 'value' => 5.50, 'bet' => 1],
['bookie' => 'StanJames', 'id_bookie' => 243649, 'value' => 1.53, 'bet' => 2],
['bookie' => 'StanJames', 'id_bookie' => 243649, 'value' => 4.00, 'bet' => 'x']
],
'Gamebookers' => [
['bookie' => 'Gamebookers', 'id_bookie' => 203620, 'value' => 5.00, 'bet' => 1],
['bookie' => 'Gamebookers', 'id_bookie' => 203620, 'value' => 1.50, 'bet' => 2],
['bookie' => 'Gamebookers', 'id_bookie' => 203620, 'value' => 4.25, 'bet' => 'x']
],
'Tipp3' => [
['bookie' => 'Tipp3', 'id_bookie' => 292604, 'value' => 4.10, 'bet' => 1],
['bookie' => 'Tipp3', 'id_bookie' => 292604, 'value' => 1.50, 'bet' => 2],
['bookie' => 'Tipp3', 'id_bookie' => 292604, 'value' => 3.40, 'bet' => 'x']
]
];
这是未排序的数组输出,但我想对行为 2 的数组进行排序,但行会发生变化,有时我必须对行为 x 或 1 的位置进行排序。
I have the following array and I want to sort the subarrays by value
.
[
'bwin' => [
['bookie' => 'bwin', 'id_bookie' => 178537, 'value' => 6.00, 'bet' => 1],
['bookie' => 'bwin', 'id_bookie' => 178537, 'value' => 1.45, 'bet' => 2],
['bookie' => 'bwin', 'id_bookie' => 178537, 'value' => 4.50, 'bet' => 'x']
],
'NordicBet' => [
['bookie' => 'NordicBet', 'id_bookie' => 201581, 'value' => 5.75, 'bet' => 1],
['bookie' => 'NordicBet', 'id_bookie' => 201581, 'value' => 1.50, 'bet' => 2],
['bookie' => 'NordicBet', 'id_bookie' => 201581, 'value' => 4.30, 'bet' => 'x']
],
'Canbet' => [
['bookie' => 'Canbet', 'id_bookie' => 176582, 'value' => 5.60, 'bet' => 1],
['bookie' => 'Canbet', 'id_bookie' => 176582, 'value' => 1.56, 'bet' => 2],
['bookie' => 'Canbet', 'id_bookie' => 176582, 'value' => 3.80, 'bet' => 'x']
],
'Expekt' => [
['bookie' => 'Expekt', 'id_bookie' => 235615, 'value' => 5.60, 'bet' => 1],
['bookie' => 'Expekt', 'id_bookie' => 235615, 'value' => 1.50, 'bet' => 2],
['bookie' => 'Expekt', 'id_bookie' => 235615, 'value' => 4.25, 'bet' => 'x']
],
'StanJames' => [
['bookie' => 'StanJames', 'id_bookie' => 243649, 'value' => 5.50, 'bet' => 1],
['bookie' => 'StanJames', 'id_bookie' => 243649, 'value' => 1.53, 'bet' => 2],
['bookie' => 'StanJames', 'id_bookie' => 243649, 'value' => 4.00, 'bet' => 'x']
],
'Gamebookers' => [
['bookie' => 'Gamebookers', 'id_bookie' => 203620, 'value' => 5.00, 'bet' => 1],
['bookie' => 'Gamebookers', 'id_bookie' => 203620, 'value' => 1.50, 'bet' => 2],
['bookie' => 'Gamebookers', 'id_bookie' => 203620, 'value' => 4.25, 'bet' => 'x']
],
'Tipp3' => [
['bookie' => 'Tipp3', 'id_bookie' => 292604, 'value' => 4.10, 'bet' => 1],
['bookie' => 'Tipp3', 'id_bookie' => 292604, 'value' => 1.50, 'bet' => 2],
['bookie' => 'Tipp3', 'id_bookie' => 292604, 'value' => 3.40, 'bet' => 'x']
]
];
This is the unsorted array output, but I want to sort the array where the line is 2, but the line will be changing, sometimes I have to sort where the line is x or 1.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
迭代集合并通过引用修改行。
调用
usort()
按value
列值对子集进行排序。代码:(演示)
Iterate over the sets and modify the rows by reference.
Call
usort()
to sort the subsets by thevalue
column values.Code: (Demo)
您可以使用
usort
。这是一个小片段。在此功能中您几乎可以做您想做的事情。You can use
usort
. Here's a small snippet. You can do pretty much want you want in this function.