0
<?php
$rate=array ( "M100B1000" => "40.00", "M1000B20000" => "80.00", "M500B10000" => "50.00", "MUnlimitedBUnlimited" => "240.00", "M5000BUnlimited" => "120.00 ") ;
ksort($rate);
print_r($rate);
?>

它提供排序率数组..

M1000B20000
M100B1000
M5000BUnlimited
M500B10000
MUnlimitedBUnlimited

我需要这种排序..

M100B1000
M500B10000
M1000B20000
M5000BUnlimited
MUnlimitedBUnlimited

给点思路...

4

1 回答 1

1

看起来你想根据字符串的大小对其进行排序,如果是的话看看这个例子

更多解释在这里http://php.net/manual/en/function.sort.php

 function shortestFirst(key($str1), key($str2)) {

        return strlen(key($str1)) - strlen(key($str2));

     }
    $rate=array ( "M100B1000" => "40.00", "M1000B20000" => "80.00", "M500B10000" => "50.00", "MUnlimitedBUnlimited" => "240.00", "M5000BUnlimited" => "120.00 "); 


    uasort($data, 'shortestFirst');
        print_r($data);
        echo '</pre>';
于 2012-04-27T05:35:26.657 回答