php 按子值对数组进行排序

发布于 2024-10-06 12:38:48 字数 622 浏览 1 评论 0原文

这是我的数组,我想我应该使用 usort 但我不知道如何让它工作。

Array
(
    [javascript] => Array
        (
            [core] => Array
                (
                    [0] => Array
                        (
                            [file] => /path/to/file.js
                            [weight] => 0
                        )

                    [1] => Array
                        (
                            [file] => /path/to/file2.js
                            [weight] => 1
                        )

                )

        )

)

我想按权重值对核心索引进行排序,其他文件和权重也会在之后添加和排序。

here is my array, I think i should be using usort but i have no idea how to get that working.

Array
(
    [javascript] => Array
        (
            [core] => Array
                (
                    [0] => Array
                        (
                            [file] => /path/to/file.js
                            [weight] => 0
                        )

                    [1] => Array
                        (
                            [file] => /path/to/file2.js
                            [weight] => 1
                        )

                )

        )

)

I would like to sort the index of core by the weight value, other files and weights will be added and sorted after also.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魔法唧唧 2024-10-13 12:38:49
usort($array['javascript']['core'], function($a, $b) {
    return $a['weight'] - $b['weight'];
});
usort($array['javascript']['core'], function($a, $b) {
    return $a['weight'] - $b['weight'];
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文