3v4l.org

run code in 300+ PHP versions simultaneously
<?php weighted_sort(array_flip(supported_types()), priority_types()); function supported_types() { static $types = 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", ); return $types; } 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. static $priority = 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 ); return $priority; } 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; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0m5Lp
function name:  (null)
number of ops:  12
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL_BY_NAME                                       'weighted_sort'
          1        INIT_FCALL                                               'array_flip'
          2        INIT_FCALL_BY_NAME                                       'supported_types'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                         $1      
          6        SEND_VAR_NO_REF_EX                                       $1
          7        INIT_FCALL_BY_NAME                                       'priority_types'
          8        DO_FCALL                                      0  $2      
          9        SEND_VAR_NO_REF_EX                                       $2
         10        DO_FCALL                                      0          
  179    11      > RETURN                                                   1

Function supported_types:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0m5Lp
function name:  supported_types
number of ops:  3
compiled vars:  !0 = $types
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   BIND_STATIC                                              !0
  117     1      > RETURN                                                   !0
  118     2*     > RETURN                                                   null

End of function supported_types

Function priority_types:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0m5Lp
function name:  priority_types
number of ops:  3
compiled vars:  !0 = $priority
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  125     0  E >   BIND_STATIC                                              !0
  138     1      > RETURN                                                   !0
  139     2*     > RETURN                                                   null

End of function priority_types

Function weighted_sort:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 40
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 40
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 23
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
2 jumps found. (Code = 46) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 39
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 39
Branch analysis from position: 37
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 29
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 34
Branch analysis from position: 31
2 jumps found. (Code = 46) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
Branch analysis from position: 37
Branch analysis from position: 34
Branch analysis from position: 18
Branch analysis from position: 40
2 jumps found. (Code = 77) Position 1 = 46, Position 2 = 55
Branch analysis from position: 46
2 jumps found. (Code = 78) Position 1 = 47, Position 2 = 55
Branch analysis from position: 47
2 jumps found. (Code = 77) Position 1 = 48, Position 2 = 53
Branch analysis from position: 48
2 jumps found. (Code = 78) Position 1 = 49, Position 2 = 53
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
Branch analysis from position: 53
Branch analysis from position: 55
2 jumps found. (Code = 44) Position 1 = 59, Position 2 = 7
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
Branch analysis from position: 55
Branch analysis from position: 40
filename:       /in/0m5Lp
function name:  weighted_sort
number of ops:  61
compiled vars:  !0 = $input, !1 = $weights, !2 = $tmp, !3 = $high, !4 = $middle, !5 = $low, !6 = $value, !7 = $key, !8 = $hasWeight, !9 = $weight, !10 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  141     0  E >   RECV                                             !0      
          1        RECV                                             !1      
  143     2        INIT_FCALL                                               'array_merge'
          3        SEND_VAL                                                 <array>
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $11     
          6        ASSIGN                                                   !2, $11
  146     7    >   ASSIGN                                                   !3, <array>
          8        ASSIGN                                                   !4, <array>
          9        ASSIGN                                                   !5, <array>
  147    10      > FE_RESET_R                                       $16     !2, ->40
         11    > > FE_FETCH_R                                       ~17     $16, !6, ->40
         12    >   ASSIGN                                                   !7, ~17
  148    13        ISSET_ISEMPTY_DIM_OBJ                         0  ~19     !1, !7
         14        ASSIGN                                           ~20     !8, ~19
         15      > JMPZ                                                     ~20, ->18
  149    16    >   FETCH_DIM_W                                      $21     !1, !7
         17        ASSIGN_REF                                               !9, $21
  152    18    >   BOOL_NOT                                         ~23     !8
         19      > JMPZ                                                     ~23, ->23
  153    20    >   ASSIGN_DIM                                               !4, !7
         21        OP_DATA                                                  !6
         22      > JMP                                                      ->34
  155    23    >   IS_SMALLER                                               0, !9
         24      > JMPZ                                                     ~25, ->29
  156    25    >   ASSIGN_DIM                                               !3, !7
         26        OP_DATA                                                  !6
  157    27        PRE_DEC                                                  !9
         28      > JMP                                                      ->34
  159    29    >   IS_SMALLER                                               !9, 0
         30      > JMPZ                                                     ~28, ->34
  160    31    >   ASSIGN_DIM                                               !5, !7
         32        OP_DATA                                                  !6
  161    33        PRE_INC                                                  !9
  164    34    > > JMPZ_EX                                          ~31     !8, ->37
         35    >   IS_IDENTICAL                                     ~32     !9, 0
         36        BOOL                                             ~31     ~32
         37    > > JMPZ                                                     ~31, ->39
  165    38    >   UNSET_DIM                                                !1, !7
  147    39    > > JMP                                                      ->11
         40    >   FE_FREE                                                  $16
  169    41        ASSIGN                                                   !2, <array>
  170    42        INIT_ARRAY                                       ~34     !3
         43        ADD_ARRAY_ELEMENT                                ~34     !4
         44        ADD_ARRAY_ELEMENT                                ~34     !5
         45      > FE_RESET_R                                       $35     ~34, ->55
         46    > > FE_FETCH_R                                               $35, !10, ->55
  171    47    > > FE_RESET_R                                       $36     !10, ->53
         48    > > FE_FETCH_R                                       ~37     $36, !6, ->53
         49    >   ASSIGN                                                   !7, ~37
  172    50        ASSIGN_DIM                                               !2, !7
         51        OP_DATA                                                  !6
  171    52      > JMP                                                      ->48
         53    >   FE_FREE                                                  $36
  170    54      > JMP                                                      ->46
         55    >   FE_FREE                                                  $35
  176    56        COUNT                                            ~40     !1
         57        IS_SMALLER                                               0, ~40
         58      > JMPNZ                                                    ~41, ->7
  178    59    > > RETURN                                                   !2
  179    60*     > RETURN                                                   null

End of function weighted_sort

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.82 ms | 1404 KiB | 17 Q