2011-09-22 22 views
0

笨排序數組值我試圖使用排序功能對array_unique功能後的數組,但我得到以下錯誤:後array_unique

A PHP Error was encountered 
Severity: Warning 
Message: implode() [function.implode]: Invalid arguments passed 
Filename: controllers/admin.php 
Line Number: 250 

下面是我的循環功能。我如何按價值升序排序?

foreach ($bars as $bar){ 

       $explode = explode(',',$bar->date_id); 
       $i = 0; 
       $b = array(); 
       foreach($explode as $bars){ 
         $bars = intval($bars); 
         @$b[$i] .= $bars; 
         $i++; 
       } 

       $date_id = array_unique($b); 
       $date_id = sort($date_id); 

       echo "<pre>"; 
       print_r($date_id); 
       echo "</pre>"; 
       $date_id = implode(',',$date_id); 
       echo "<pre>"; 
       print_r($date_id); 
       echo "</pre>"; 
} 

回答

3

其中看起來歪你的代碼,sort()返回true或false,而不是排序後的數組其他的事情。

取而代之的是:

$date_id = array_unique($b); 
$date_id = sort($date_id); 

使用此:

$date_id = array_unique($b); 
sort($date_id);