PHP:使用非字母和非数字键对数组进行排序
我正在尝试使用 PHP 的 ksort 来对这个数组进行排序:
Array(
[district_name] => District name
[email] => [email protected]
[name] => Name of item
[number] => 191
[phone] => +41234568789
[{attr}id] => 2
[questions] => Array(...)
)
但是包含 {attr}...
的键没有被排序,它保留在同一个位置,而其他键被排序。对该数组进行排序的最佳方法是什么?
I'm trying to use PHP's ksort to sort this array:
Array(
[district_name] => District name
[email] => [email protected]
[name] => Name of item
[number] => 191
[phone] => +41234568789
[{attr}id] => 2
[questions] => Array(...)
)
But the key that contains {attr}...
does not get sorted, it stays at the same place while the other keys gets sorted. What is the best method to sort this array?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法证实这一点。此代码按预期排序(“{attr}id”位于结果数组中的最后):
请确保您的源数组没问题。
I can't confirm this. This code sorts as expected ("{attr}id" is last in the resulting array):
Please make sure your source array is okay.