PHP使用升序数组值启动


PHP usort by ascending array value

下面是我的数组的一部分

我试着使用下面的函数按升序对其进行排序然而,它似乎隆隆作响,页面并没有处于增量状态。

我不确定我的排序比较器功能(cmp)出了什么问题

function cmp($a, $b) {
    return $a['page'] - $b['page'];
}

usort($chapter_result_array,"cmp");
$chapter_result_array = array_reverse($chapter_result_array);

[11] => Array
    (
        [link] => https://www.mywebsite.com/projects/funny-story/chapter-8-1.1046/
        [page] => 8.1
    )
[12] => Array
    (
        [link] => https://www.mywebsite.com/projects/funny-story/chapter-8-2.1085/
        [page] => 8.2
    )
[13] => Array
    (
        [link] => https://www.mywebsite.com/projects/funny-story/chapter-9-1.1114/
        [page] => 9.1
    )
[14] => Array
    (
        [link] => https://www.mywebsite.com/projects/funny-story/chapter-6-1.890/
        [page] => 6.1
    )
[15] => Array
    (
        [link] => https://www.mywebsite.com/projects/funny-story/chapter-6-2.995/
        [page] => 6.2
    )
[16] => Array
    (
        [link] => https://www.mywebsite.com/projects/funny-story/chapter-7-1.1020/
        [page] => 7.1
    )
[17] => Array
    (
        [link] => https://www.mywebsite.com/projects/funny-story/chapter-5-1.855/
        [page] => 5.1
    )

我猜页面不是float值,而是更像"版本字符串",所以你应该与版本比较进行比较:比较PHP 中的两个版本字符串

它将返回-1、0或1,就像预期使用的usort一样。