在php中对多维数组进行排序

问题描述 投票:0回答:1

我有以下数组,我想根据“lastfirma”值进行排序。所以下面的数组:

Array
(
    [000002] => Array
        (
            [clients] => Array
                (
                    [556046-2222] => Array
                        (
                            [lastfirma] => Name 1
                            [periods] => Array
                                (
                                    [1] => Array
                                        (
                                            [userId] => 000015
                                            [start] => 2020-05-01
                                            [end] => 2021-04-30
                                        )
                                    [2] => Array
                                        (
                                            [userId] => 105779
                                            [start] => 2021-05-01
                                            [end] => 2022-04-30
                                        )
                                )
                        )
                    [556892-1111] => Array
                        (
                            [lastfirma] => Anomaly
                             [periods] => Array
                                (
                                    [1] => Array
                                        (
                                            [userId] => 000015
                                            [start] => 2020-05-01
                                            [end] => 2021-04-30
                                        )
                                    [2] => Array
                                        (
                                            [userId] => 105779
                                            [start] => 2021-05-01
                                            [end] => 2022-04-30
                                        )
                                )
                        )
                )
        )
)

会变成

Array
(
    [000002] => Array
        (
            [clients] => Array
                (
                    [556892-1111] => Array
                        (
                            [lastfirma] => Anomaly
                             [periods] => Array
                                (
                                    [1] => Array
                                        (
                                            [userId] => 000015
                                            [start] => 2020-05-01
                                            [end] => 2021-04-30
                                        )
                                    [2] => Array
                                        (
                                            [userId] => 105779
                                            [start] => 2021-05-01
                                            [end] => 2022-04-30
                                        )
                                )
                        )
                    [556046-2222] => Array
                        (
                            [lastfirma] => Name 1
                            [periods] => Array
                                (
                                    [1] => Array
                                        (
                                            [userId] => 000015
                                            [start] => 2020-05-01
                                            [end] => 2021-04-30
                                        )
                                    [2] => Array
                                        (
                                            [userId] => 105779
                                            [start] => 2021-05-01
                                            [end] => 2022-04-30
                                        )
                                )
                        )
                )
        )
)
php sorting multidimensional-array
1个回答
0
投票
krsort($input['000002']['clients']);
© www.soinside.com 2019 - 2024. All rights reserved.