<?php
weighted_sort(array_flip(supported_types()), priority_types());
function supported_types()
{
return array(
1 => "Terraced House",
2 => "End of terrace house",
3 => "Semi-detached house",
4 => "Detached house",
5 => "Mews house",
6 => "Cluster house",
7 => "Ground floor flat",
8 => "Flat",
9 => "Studio flat",
10 => "Ground floor maisonette",
11 => "Maisonette",
12 => "Bungalow",
13 => "Terraced bungalow",
14 => "Semi-detached bungalow",
15 => "Detached bungalow",
16 => "Mobile home",
20 => "Land",
21 => "Link detached house",
22 => "Town house",
23 => "Cottage",
24 => "Chalet",
26 => "House",
27 => "Villa",
28 => "Apartment",
29 => "Penthouse",
30 => "Finca",
43 => "Barn Conversion",
44 => "Serviced apartment",
45 => "Parking",
46 => "Sheltered Housing",
47 => "Retirement property",
48 => "House share",
49 => "Flat share",
50 => "Park home",
51 => "Garages",
52 => "Farm House",
53 => "Equestrian facility",
56 => "Duplex",
59 => "Triplex",
62 => "Longere",
65 => "Gite",
68 => "Barn",
71 => "Trulli",
74 => "Mill",
77 => "Ruins",
80 => "Restaurant",
83 => "Cafe",
86 => "Mill",
92 => "Castle",
95 => "Village House",
101 => "Cave House",
104 => "Cortijo",
107 => "Farm Land",
110 => "Plot",
113 => "Country House",
116 => "Stone House",
117 => "Caravan",
118 => "Lodge",
119 => "Log Cabin",
120 => "Manor House",
121 => "Stately Home",
125 => "Off-Plan",
128 => "Semi-detached Villa",
131 => "Detached Villa",
134 => "Bar/Nightclub",
137 => "Shop",
140 => "Riad",
141 => "House Boat",
142 => "Hotel Room",
143 => "Block of Apartments",
144 => "Private Halls",
178 => "Office",
181 => "Business Park",
184 => "Serviced Office",
187 => "Retail Property (High Street)",
190 => "Retail Property (Out of Town)",
193 => "Convenience Store",
196 => "Garages",
199 => "Hairdresser/Barber Shop",
202 => "Hotel",
205 => "Petrol Station",
208 => "Post Office",
211 => "Pub",
214 => "Workshop & Retail Space",
217 => "Distribution Warehouse",
220 => "Factory",
223 => "Heavy Industrial",
226 => "Industrial Park",
229 => "Light Industrial",
232 => "Storage",
235 => "Showroom",
238 => "Warehouse",
241 => "Land",
244 => "Commercial Development",
247 => "Industrial Development",
250 => "Residential Development",
253 => "Commercial Property",
256 => "Data Centre",
259 => "Farm",
262 => "Healthcare Facility",
265 => "Marine Property",
268 => "Mixed Use",
271 => "Research & Development Facility",
274 => "Science Park",
277 => "Guest House",
280 => "Hospitality",
283 => "Leisure Facility",
);
}
function priority_types()
{
// Types that should take elevated priority.
// This could also be defined in config so that clients can choose a priority
// for items which may help reduce some confusion.
return array(
"Terraced bungalow" => 2,
"Semi-detached bungalow" => 2,
"Detached bungalow" => 2,
"Studio flat" => 1,
"Equestrian facility" => 1,
"Bungalow" => 1,
"Retirement property" => 1,
"Barn Conversion" => 1,
"Apartment" => 1,
"Garages" => -1
);
}
function weighted_sort(array $input, array $weights)
{
$tmp = array_merge(array(), $input);
do {
$high = array(); $middle = array(); $low = array();
foreach ($tmp as $key => $value) {
if (($hasWeight = isset($weights[$key]))) {
$weight =& $weights[$key];
}
if (!$hasWeight) {
$middle[$key] = $value;
} else if ($weight > 0) {
$high[$key] = $value;
$weight--;
} else if ($weight < 0) {
$low[$key] = $value;
$weight++;
}
if ($hasWeight && $weight === 0) {
unset($weights[$key]);
}
}
$tmp = array();
foreach (array($high, $middle, $low) as $array) {
foreach ($array as $key => $value) {
$tmp[$key] = $value;
}
}
} while (count($weights) > 0);
return $tmp;
}
preferences:
35.82 ms | 402 KiB | 5 Q