【发布时间】:2018-09-28 10:27:30
【问题描述】:
我找不到关于这个的东西,可能我错过了,但我想过滤/排序一个数组,它有一个我想移到顶部的键,所以它将是第一项。在我的示例中,我希望键 3 移到顶部。有没有简单的方法可以做到这一点?
// at default
[
"key 1" : [ more data ],
"key 2" : [ even more data ],
"key 3" : [ some data ],// for this example I want this to be the first item
"key 4" : [ where is the data ]
]
// how i want it to be
move_to_first_in_array($array , 'key 3');
[
"key 3" : [ some data ],// for this example I want this to be the first item
"key 1" : [ more data ],
"key 2" : [ even more data ],
"key 4" : [ where is the data ]
]
【问题讨论】:
-
您必须提供过滤数组的条件
-
不,它不是重复的
-
@user759235 但为什么不是......这就是你想要的?
-
我现在提供了一个例子
标签: php