开发者

Sorting a associative array

开发者 https://www.devze.com 2023-02-15 14:18 出处:网络
I have an associative array of format [Article_title_1] => Array ( [description] =>开发者_开发问答; Trial

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.


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:

Article_Title_12
Article_title_1
Article_title_10
Article_title_11
Article_title_2
Article_title_3
Article_title_4
Article_title_5
Article_title_6
Article_title_7
Article_title_8
Article_title_9

If this is your problem, then you will need to use uksort() with a custom comparison function

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号