PHP:按键将asort数组作为具有特殊字符的字符串

时间:2016-04-14 13:20:49

标签: php arrays sorting

我有一个像这样的多维数组:

$myArray = Array
(
    "MwSt. 7%" => Array
        (
            "[rates]" => Array
                (
                    "[0]" => Array
                        (
                            "[code]" => "MwSt. 19%",
                            "[title]" => "MwSt. 19%",
                            "[percent]" => 19,
                            "[position]" => 2,
                            "[priority]" => 20,
                            "[rule_id]" => 6
                        )

                )
        ),

    "MwSt. 19%" => Array
        (
            "[rates]" => Array
                (
                    "[0]" => Array
                        (
                            "[code]" => "MwSt. 7%",
                            "[title]" => "MwSt. 7%",
                            "[percent]" => 7,
                            "[position]" => 1,
                            "[priority]" => 10,
                            "[rule_id]" => 7
                        )

                )
        )

);

我想做的是始终将“MwSt.7%”作为第一把钥匙然后“MwSt.19%”

我的功能仅在我的数组以“MwSt.19%”开头时才有效,但当它以“MwSt.7%”开头时,我的排序错误。

asort($myArray, SORT_STRING);

有任何帮助吗?

1 个答案:

答案 0 :(得分:0)

ksort($myArray); 

是解决方案;)