我有兩個數組,最小值和最大值。我想做foreach循環,如果最小值和最大值匹配,那麼只顯示最大值,如果兩個值不匹配,則分別顯示最小值和最大值。我想匹配最小值和最大值的關鍵。我沒有得到如何比較兩個值。我有這個陣列如何在javascript中比較兩個數組的值
var interestRateMin = [];
data.forEach(function(element){
this.push(element.interestRateMin);
}, interestRateMin);
var interestRateMax = [];
data.forEach(function(element){
this.push(element.interestRateMax);
}, interestRateMax);
這是我得到的數組值。
MinRate = ["10.0", "11.5", "12.0", "12.0", "12.0", "12.0", "12.0", "12.25", "12.5", "12.75", "12.75", "13.0", "13.0", "13.25", "13.5", "13.75", "14.0", "14.0"]
MaxRate = ["10.0", "11.75", "12.0", "12.0", "24.0", "12.0", "12.0", "12.25", "12.5", "12.75", "12.75", "13.0", "13.0", "13.25", "17.0", "13.75", "14.0", "14.0"]
我想達到同樣的事情,但在JavaScript中。
<?php
foreach ($json['resultList'] as $key=>$value) {
if($json["resultList"][$key]["MinRate"] == $json["resultList"][$key]["MaxRate"]){
$interest = $json["resultList"][$key]["MinRate"];
}
else{
$interest = $json["resultList"][$key]["MinRate"].' - '.$json["resultList"][$key]["MaxRate"];
}
if($json["resultList"][$key]["MinPercentage"] == $json["resultList"][$key]["MaxPercentage"]){
$financing = $json["resultList"][$key]["MinPercentage"];
}
else{
$financing = $json["resultList"][$key]["MinPercentage"].' - '.$json["resultList"][$key]["MaxPercentage"];
}
}
?>
請加'只顯示想要的結果...'。這怎麼發生? –