我目前使用这个PHP从soap feed中获取数据,无论如何我是否使用来自$ weekrent的数据从高到低排序?
任何帮助都会很棒!这是我的PHP代码:
<?php
$wsdl = "http://portal.letmc.com/PropertySearchService.asmx?WSDL";
$client = new SoapClient($wsdl, array ("trace"=>1, "exceptions"=>0));
$strClientID = "{0050-e58a-cd32-3771}";
$strBranchID = "{0004-e58a-cd32-399e}";
$strAreaID = $_GET['area'];
$nMaxResults = $_GET['perpage'];
$nRentMinimum = $_GET['minrent'];
$nRentMaximum = $_GET['maxrent'];
$nMaximumTenants = $_GET['numtennants'];
$parameters = array( "strClientID"=>$strClientID,
"strBranchID"=>$strBranchID,
"strAreaID"=>$strAreaID,
"nMaxResults"=>$nMaxResults,
"nRentMinimum"=>$nRentMinimum,
"nRentMaximum"=>$nRentMaximum,
"nMaximumTenants"=>$nMaximumTenants
);
$values = $client->SearchProperties($parameters);
if(!is_array($values->SearchPropertiesResult->PropertyInfo))
{
$values->SearchPropertiesResult->PropertyInfo = array($values->SearchPropertiesResult->PropertyInfo);
}
if($values != '')
{
foreach ($values->SearchPropertiesResult->PropertyInfo as $message)
{
$uglyid = $message->ID;
$id = $message->FriendlyID;
$mainphoto = $message->MainPhoto->PhotoUrl;
$furnished = $message->Furnished;
$addressline1 = $message->Address1;
$rooms = $message->MaxTenants;
$rent = $message->Rent;
$description = $message->Description;
$isletagreed = $message->IsLetAgreed;
$facilities = $message->Facilities->FacilityInfo;
$photos = $message->Photos->PhotoInfo;
$roomsinfo = $message->Rooms->RoomInfo;
$facilitiesstring = serialize($facilities);
$extractnumbers = ereg_replace("[^0-9]", "", $rent);
$monthrent = ($extractnumbers) / $rooms;
$monthrentrounded = number_format(($monthrent/100),2);
$weekrent = ($monthrentrounded) * 12 / 52;
$weekrentrounded = floor($weekrent * 100) / 100;
$roomsinfojson = json_encode($roomsinfo);
$facilitiesjson = json_encode($facilities);
$roomsinfodouble = (substr_count(strip_tags($roomsinfojson),"Double"));
$roomsinfosingle = (substr_count(strip_tags($roomsinfojson),"Single"));
$roomsinfobathroom = (substr_count(strip_tags($roomsinfojson),"Bathroom"));
$roomsinfoshower = (substr_count(strip_tags($roomsinfojson),"Shower"));
$facilitiesparking = (substr_count(strip_tags($facilitiesjson),"Parking"));
$facilitiesgarden = (substr_count(strip_tags($facilitiesjson),"Garden"));
$totalbathrooms = $roomsinfobathroom + $roomsinfoshower;
$totalimages = count($photos);
echo '
<div class="col-property-box col-property-box-1-3">
<div class="owl-property-box">';
$i=0; foreach ($photos as $data) { if($i==4) break; echo '<div class="property-grid-box-picture" style="background: url('. $data->PhotoUrl .') center center;"></div>'; $i++; };
echo '</div>
<div class="property-grid-box">
<a href="http://www.stla.co.uk/properties/show/?id='. $uglyid .'" class="property-grid-box-title">'. $addressline1 .'</a>
<p class="property-grid-box-text">'. limit_words($description,19) .'...</p>
<div class="property-grid-box-price">
<div class="section group">
<div class="col col-property-box-1-2 property-grid-box-price-border-right">
<div class="property-grid-box-price-top">£'. $weekrentrounded.'pp</div> <div class="property-grid-box-price-under">Weekly</div>
</div>
<div class="col col-property-box-1-2">
<div class="property-grid-box-price-top">£'. $monthrentrounded .'pp</div> <div class="property-grid-box-price-under">Monthly</div>
</div>
</div>
</div>
<div class="property-grid-box-icon-box">
<div class="section group">
<div class="col col-1-3-border no-left-border">
<span class="property-grid-box-number-icon"><center><i class="fa fa-bed"></i></center><div class="property-grid-box-number-text">'. $rooms .'</div></span>
</div>
<div class="col col-1-3-border">
<span class="property-grid-box-number-icon"><center><i class="flaticon-shower5"></i></center><div class="property-grid-box-number-text">'. $totalbathrooms .'</div></span>
</div>
<div class="col col-1-3-border">
<span class="property-grid-box-number-icon"><center><i class="flaticon-beds12"></i></center><div class="property-grid-box-number-text">'. $totalimages .'</div></span>
</div>
</div>
</div>
</div>
</div>
';
}
}
function limit_words($string, $word_limit)
{
$words = explode(" ",$string);
return implode(" ",array_splice($words,0,$word_limit));
}
?>
答案 0 :(得分:0)
你可以使用usort函数..所以你得到了排序结果
答案 1 :(得分:0)
您可以将您的消息数据与计算的周期一起放入临时数组,然后使用usort对周期值进行排序
if($values != '')
{
$arrayForSort = array();
foreach ($values->SearchPropertiesResult->PropertyInfo as $message) {
$rent = $message->Rent;
$rooms = $message->MaxTenants;
$extractnumbers = ereg_replace("[^0-9]", "", $rent);
$monthrent = ($extractnumbers) / $rooms;
$monthrentrounded = number_format(($monthrent/100),2);
$weekrent = ($monthrentrounded) * 12 / 52;
$arrayForSort[] = array('weekrent' => $weekrent, 'message' => $message);
}
usort($arrayForSort, function($a, $b) {
if ($a['weekrent'] == $b['weekrent']) {
return 0;
}
return ($a['weekrent'] > $b['weekrent']) ? -1 : 1;
});
foreach ($arrayForSort as $item)
{
$message = $item['message'];
// Your code here to proper process the message ...