私はこの配列を持っています。 json print_r($json_array);
で値を取得していますが、この配列をソートしたいのですが、配列を呼び出す方法がわかりません。私は自分のWebサービスの結果をソートしようとしています。私は投稿した配列結果を取得しています。また、金利の最小値と最大値を使用しました。昇順にソートしたいjavascriptで並べ替える配列
ソートするためにドロップダウンオプション配列を選択したいと思います。レートタイプを選択している場合と同様に、結果はアルファベットのレートタイプを表示します。
HTML
<select id="sort-by" class="sort-by" name="sortBy">
<option value="1">Bank/Product Name</option>
<option value="2">Interest Rate (% p.a.)</option>
<option id="financing" value="3">Financing (in %)</option>
<option value="4">Maximum Loan Amount</option>
<option value="5">Max Tenure (In Years)</option>
<option value="6" onclick="myFunction()" id="rateType" >Interest Rate Type</option>
</select>
のWebサービスを介して生成されたアレイは
Array (
[0] => Array (
[rateType] => Fixed
[interestRateMin] => 12.0
[financingPercentageMax] => 80
[interestRateMax] => 12.0
[financingPercentageMin] => 60
[bankName] => Muthoot Finance
[repaymentTenureInYears] => 0.25 [age] => 32
[maxLoanAmt] => 10000000
)
[1] => Array (
[rateType] => Fixed
[interestRateMin] => 12.0
[financingPercentageMax] => 93
[interestRateMax] => 24.0
[financingPercentageMin] => 88
[bankName] => Manappuram Finance
[repaymentTenureInYears] => 1
[maxLoanAmt] => 10000000
)
[2] => Array (
[rateType] => Floating
[interestRateMin] => 13.75
[financingPercentageMax] => 80
[interestRateMax] => 13.75
[financingPercentageMin] => 80
[bankName] => South Indian Bank- Gold Power
[repaymentTenureInYears] => 1 [age] => 32
[maxLoanAmt] => 10000000
)
[3] => Array (
[rateType] => Floating
[interestRateMin] => 14.0
[financingPercentageMax] => 90
[interestRateMax] => 14.0
[financingPercentageMin] => 90
[bankName] => HDFC Bank - Gold Loan
[repaymentTenureInYears] => 1
[maxLoanAmt] => 10000000
)
[4] => Array (
[rateType] => Floating
[interestRateMin] => 14.0
[financingPercentageMax] => 80
[interestRateMax] => 14.0
[financingPercentageMin] => 80
[bankName] => South Indian Bank- Gold rush
[repaymentTenureInYears] => 1
[maxLoanAmt] => 10000000
)
)
PHP
<?php
if($_POST["occupation"] == '1'){
$occupation = 'Salaried';
}
else{
$occupation = 'Self+Employed';
}
$url = 'http://ppp.psp.com/ajaxv2/getCompareResults.html?rateType='.$_POST["rateType"].'&occupation='.$_POST["occupation"].'&offeringTypeId='.$_POST["offeringTypeId"].'&city='.$_POST["city"].'&loanAmt='.$_POST["loanAmt"].'&q='.$_POST["q"].'&productId='.$_POST["product_id"].'&age='.$_POST["age"];
//echo $url;
// Initiate curl
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);
$json = json_decode($result, true);
//print_r($json);
//echo $json['resultList'];
//echo $json['resultList']['interestRateMin'];
$json_array = $json['resultList'];
//print_r($json_array);
?>
<?php if(count($json['resultList']) > 0): ?>
<?php
foreach ($json['resultList'] as $key=>$value) {
if($json["resultList"][$key]["interestRateMin"] == $json["resultList"][$key]["interestRateMax"]){
$interest = $json["resultList"][$key]["interestRateMin"];
}
else{
$interest = $json["resultList"][$key]["interestRateMin"].' - '.$json["resultList"][$key]["interestRateMax"];
}
if($json["resultList"][$key]["financingPercentageMin"] == $json["resultList"][$key]["financingPercentageMax"]){
$financing = $json["resultList"][$key]["financingPercentageMin"];
}
else{
$financing = $json["resultList"][$key]["financingPercentageMin"].' - '.$json["resultList"][$key]["financingPercentageMax"];
}
echo '
<div class="cr-content">
<div class="bank-rates">
<ul>
<li>
<div class="innr-spl" style="padding: 5px 0;">
<span style="display:block;"><img src="'.$json["resultList"][$key]["imageUrl"].'"></span>
<span class="hide">'.$json["resultList"][$key]["bankName"].'</span>
</div>
</li>
<li><div class="innr-spl2">' . $interest . '%' . '</div></li>
<li><div class="innr-spl2">' . $financing . '</div></li>
<li class="hide"><div class="innr-spl3 kmore" id="'.$key.'"><i class="fa fa-chevron-circle-down" aria-hidden="true"></i>View Datails</div> </li>
</ul>
<div style="clear:both"></div>
<ul class="details" id="ban_'.$key.'">
<li><i class="fa fa-thumbs-o-up" aria-hidden="true"></i> Maximum Loan Amount : '.$json["resultList"][$key]["maxLoanAmt"].'</li>
<li><i class="fa fa-thumbs-o-up" aria-hidden="true"></i> Max Tenure (In Years) : '.$json["resultList"][$key]["repaymentTenureInYears"].'</li>
<li><i class="fa fa-thumbs-o-up" aria-hidden="true"></i> Interest Rate Type : '.$json["resultList"][$key]["rateType"].'</li>
</ul>
</div>
</div>
';
$i++;
}
?>
<?php endif;?>
var data = [{}]これは取得していない – user6924814
これは空のjson(オブジェクト)で配列を作成します。 –
@ user6924814、何らかの形でクライアント側にデータを取得しますか?それを並べ替えて、テーブルや他のスタイルに戻して表示することができます。 –