基本上标题就是问题本身。我有一个集合,它在一个字段中存储数组。我做了一个排序算法来整理那些数组,结果是排序数组:
array:8 [▼
3 => array:5 [▼
5 => 100
1 => 50
2 => 30
3 => 20
4 => 10
]
6 => array:5 [▼
1 => 100
5 => 50
3 => 30
4 => 20
2 => 10
]
2 => array:5 [▼
3 => 100
5 => 50
4 => 30
1 => 20
2 => 10
]
此数组3,6,2的索引是集合的ID。如何根据此ID以与数组相同的顺序订购集合?
答案 0 :(得分:2)
假设您在private CompositeDisposable mSubscriptions;
@Override
public void onCreate(Bundle savedInstanceState) {
...
mSubscriptions = new CompositeDisposable();
...
}
@Override
protected void onPause() {
super.onPause();
mSubscriptions.clear();
}
public void someMethodForButtonClick(View view) {
IwcRepository iwcRepository =
Injection.provideIwcRepository(getApplication());
mSubscriptions.add(iwcRepository.getSomeCompletable()
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableCompletableObserver() {
@Override
public void onComplete() {
}
@Override
public void onError(@NonNull Throwable e) {
}
}));
}
变量中有数组:
$a
然后您可以参考来自$a = array:8 [▼
3 => array:5 [▼
5 => 100
1 => 50
2 => 30
3 => 20
4 => 10
]
6 => array:5 [▼
1 => 100
5 => 50
3 => 30
4 => 20
2 => 10
]
2 => array:5 [▼
3 => 100
5 => 50
4 => 30
1 => 20
2 => 10
]
];
的密钥按升序排序,并具有以下内容:
ksort()
类似地,对于降序,您可以使用foreach($a as $b)
{
ksort($b);
}
。
希望这有帮助。