我有一個數組循環:顯示計數器
陣列功能:
$truckTypesArray = array(
"1" => "03 m3",
"2" => "05 m3",
"3" => "08 m3",
"4" => "10 m3",
"5" => "12 m3",
"6" => "14 m3",
"7" => "20 m3",
"8" => "20 m3 Hayon",
);
function getTruckTypes($truckTypesArray, $id)
{
return $truckTypesArray[$id];
}
循環代碼:
while($fetchPresentTruckTypes = mysql_fetch_array($getTruckTypeQuery))
{
$createTruckTypeArray[] = getTruckTypes($truckTypesArray, $fetchPresentTruckTypes['truckTypeId']);
}
$allTructTypes = implode(",",$createTruckTypeArray);
現在它產生這個輸出很好:
20 m3, 03 m3, 20 m3, 10 m3, 20 m3,
我希望它看起來是這樣的:
20 m3 = 3,
03 m3 = 1,
10 m3 = 1
試一下array_count_values() –