2 回答

TA貢獻1906條經(jīng)驗 獲得超10個贊
因此,為了對數(shù)組進行排序,我需要使用 usort,其中每個數(shù)組中的鍵名稱應(yīng)該相同。
所以我將 $isi 變量更改為
$isi = ["value"=>$confidence*$support,"key"=>$key];
然后使用這個 usort 函數(shù)對數(shù)組進行排序
usort($array,function($a,$b){
return $a["value"] < $b["value"];
})
然后為了從數(shù)據(jù)庫中獲得 4 個最高的乘積,對代碼進行輕微的更改
$i = 0;
foreach($array as $key => $value){
if($i == 0){
$product1 = product::find($value['key']);
}
else if($i == 1){
$product2 = product::find($value['key']);
}
else if($i == 2){
$product3 = product::find($value['key']);
}
else if($i == 3){
$product4 = product::find($value['key']);
}
$i++;
}
- 2 回答
- 0 關(guān)注
- 126 瀏覽
添加回答
舉報