对关联数组进行排序
我有一个格式的关联数组,
[Article_title_1] => Array
(
[description] => Trial
[created] => date
)
[Article_title_2] => Array
(
[description] => Trial
[created] => date
)
我想按字母顺序(按标题)对数组进行排序,其中 Article_title_2 是文章的标题。
我尝试过排序。它不起作用。我试图使用 cakephp 的集合排序,也无法让它工作。
我很感激任何帮助。
谢谢。
I have an associative array of format
[Article_title_1] => Array
(
[description] => Trial
[created] => date
)
[Article_title_2] => Array
(
[description] => Trial
[created] => date
)
I want sort the array in alphabetical order(by title) where Article_title_2 is the title of the article.
I tried ksort. It does not work. I was trying to use cakephp's set sort, could not get it to work either.
I appreciate any help.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ksort() 会将每个键视为一个字符串,因此它将根据正常的字符串排序规则进行排序,并且区分大小写。这意味着您最终可能会得到:
如果这是您的问题,那么您将需要使用 uksort () 带有自定义比较函数
ksort() will treat each of your keys as a string, so it will sort according to normal string ordering rules, and is case-sensitive. This means you could end up with:
If this is your problem, then you will need to use uksort() with a custom comparison function