到目前为止,我的所有研究都表明,如果不编写冗长的函数(例如这里的解决方案),就无法实现这一点。是否有更简单的方法可以使用预定义的PHP函数来实现呢?
只是为了明确,我正在尝试做以下事情:
我查看了以下函数,但迄今为止还没有能够自己编写出解决方案。
只是为了明确,我正在尝试做以下事情:
$test = array(
'bla' => 123,
'bla2' => 1234,
'bla3' => 12345
);
// Call some cool function here and return the array where the
// the element with key 'bla2' has been shifted to the beginning like so
print_r($test);
// Prints bla2=1234, bla=>123 etc...
我查看了以下函数,但迄今为止还没有能够自己编写出解决方案。
总结
我想要:
- 将一个元素移动到数组的开头
- ... 同时保留关联数组键