fork download
  1. <?php
  2.  
  3. $data = [
  4. "lut_avy_aspect" => ["description" => "Avalanche Obs Aspect List", "key" => "code", "label" => "label", "sortorder" => "listorder"],
  5. "lut_boolean" => ["description" => "Boolean Data", "key" => "code", "label" => "label", "sortorder" => "listorder"],
  6. "lut_avy_bedsurface" => ["description" => "Avalanche Bed Surface Type", "key" => "code", "label" => "code,label", "sortorder" => "listorder"],
  7. "lut_avy_paths" => ["description" => "Avalanche Paths", "key" => "code", "label" => "label", "sortorder" => "listorder"],
  8. "lut_avy_size_destructiveforce" => ["description" => "Avalanche Destructive Force", "key" => "code", "label" => "code,label", "sortorder" => "listorder"],
  9. "lut_avy_size_relativetopath" => ["description" => "Avalanche Relative Path Size", "key" => "code", "label" => "label", "sortorder" => "listorder"],
  10. "lut_avy_startzone_horiz" => ["description" => "Start Zone Horizontal Measure", "key" => "code", "label" => "code,label", "sortorder" => "listorder"],
  11. "lut_avy_startzone_vert" => ["description" => "Start Zone Vertical Measure", "key" => "code", "label" => "code,label", "sortorder" => "listorder"],
  12. "lut_avy_termdebris_detailed" => ["description" => "Avalanche Debris (Detailed)", "key" => "code", "label" => "code,label", "sortorder" => "listorder"],
  13. "lut_avy_termdebris_long" => ["description" => "Long Avalanche Debris", "key" => "code", "label" => "code,label", "sortorder" => "listorder"],
  14. "lut_avy_termdebris_short" => ["description" => "Short Avalanche Debris", "key" => "code", "label" => "code,label", "sortorder" => "listorder"],
  15. "lut_avy_terminusmoisture" => ["description" => "Avalanche Terminus Moisture", "key" => "code", "label" => "label", "sortorder" => "listorder"],
  16. "lut_avy_triggers" => ["description" => "Avalanche Trigger Types", "key" => "code", "label" => "code,label", "sortorder" => "code"],
  17. "lut_avy_triggers_humanmod" => ["description" => "Human Modified Triggers", "key" => "code", "label" => "label", "sortorder" => "listorder"],
  18. "lut_avy_trigtypes" => ["description" => "Avalanche Trigger Types", "key" => "code", "label" => "label", "sortorder" => "listorder"],
  19. "lut_avy_types" => ["description" => "Avalanche Types", "key" => "code", "label" => "label", "sortorder" => "listorder"],
  20. "lut_obs_observers" => ["description" => "Observer List", "key" => "observer_id", "label" => "obs_lname", "sortorder" => "observer_id"],
  21. "lut_obs_seasons" => ["description" => "Observed Seasons", "key" => "season_id", "label" => "season_text", "sortorder" => "season_text"],
  22. "lut_wx_airtemptrends" => ["description" => "Air Temperature Trends", "key" => "code", "label" => "label", "sortorder" => "listorder"],
  23. "lut_wx_preciprate" => ["description" => "Precipitation Rates", "key" => "code", "label" => "label", "sortorder" => "listorder"],
  24. "lut_wx_preciprate_rain" => ["description" => "Rain Precipitation Rate", "key" => "code", "label" => "label", "sortorder" => "listorder"],
  25. "lut_wx_preciprate_snow" => ["description" => "Snow Precipitation Rate", "key" => "code", "label" => "label", "sortorder" => "listorder"],
  26. "lut_wx_preciptype" => ["description" => "Precipitation Type", "key" => "code", "label" => "label", "sortorder" => "listorder"],
  27. "lut_wx_pressuretrends" => ["description" => "Pressure Trends", "key" => "code", "label" => "label", "sortorder" => "listorder"],
  28. "lut_wx_skyconditions" => ["description" => "Sky Conditions", "key" => "code", "label" => "label", "sortorder" => "listorder"],
  29. "lut_wx_snow_ground" => ["description" => "Ground Snow Conditions", "key" => "code", "label" => "label", "sortorder" => "listorder"],
  30. "lut_wx_snow_surface" => ["description" => "Surface Snow Conditions", "key" => "code", "label" => "label", "sortorder" => "listorder"],
  31. "lut_wx_weatherlocations" => ["description" => "Weather Observation Locations", "key" => "code", "label" => "label", "sortorder" => "listorder"],
  32. "lut_wx_wind_blowingridgetops" => ["description" => "Ridgetop Wind Blowing Conditions", "key" => "code", "label" => "label", "sortorder" => "listorder"],
  33. "lut_wx_wind_snowdirection" => ["description" => "Snow Wind Direction", "key" => "code", "label" => "label", "sortorder" => "listorder"],
  34. "lut_wx_wind_speedestimates" => ["description" => "Estimated Wind Speeds", "key" => "code", "label" => "label", "sortorder" => "listorder"]
  35. ];
  36.  
  37. usort($data, make_comparer('name'));
  38. print_r($data);
  39.  
  40.  
  41. function make_comparer() {
  42. // Normalize criteria up front so that the comparer finds everything tidy
  43. $criteria = func_get_args();
  44. foreach ($criteria as $index => $criterion) {
  45. $criteria[$index] = is_array($criterion)
  46. ? array_pad($criterion, 3, null)
  47. : array($criterion, SORT_ASC, null);
  48. }
  49.  
  50. return function($first, $second) use ($criteria) {
  51. foreach ($criteria as $criterion) {
  52. // How will we compare this round?
  53. list($column, $sortOrder, $projection) = $criterion;
  54. $sortOrder = $sortOrder === SORT_DESC ? -1 : 1;
  55.  
  56. // If a projection was defined project the values now
  57. if ($projection) {
  58. $lhs = call_user_func($projection, $first[$column]);
  59. $rhs = call_user_func($projection, $second[$column]);
  60. }
  61. else {
  62. $lhs = $first[$column];
  63. $rhs = $second[$column];
  64. }
  65.  
  66. // Do the actual comparison; do not return if equal
  67. if ($lhs < $rhs) {
  68. return -1 * $sortOrder;
  69. }
  70. else if ($lhs > $rhs) {
  71. return 1 * $sortOrder;
  72. }
  73. }
  74.  
  75. return 0; // tiebreakers exhausted, so $first == $second
  76. };
  77. }
  78.  
Success #stdin #stdout #stderr 0.03s 26072KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Array
        (
            [description] => Avalanche Obs Aspect List
            [key] => code
            [label] => label
            [sortorder] => listorder
        )

    [1] => Array
        (
            [description] => Observer List
            [key] => observer_id
            [label] => obs_lname
            [sortorder] => observer_id
        )

    [2] => Array
        (
            [description] => Snow Wind Direction
            [key] => code
            [label] => label
            [sortorder] => listorder
        )

    [3] => Array
        (
            [description] => Ridgetop Wind Blowing Conditions
            [key] => code
            [label] => label
            [sortorder] => listorder
        )

    [4] => Array
        (
            [description] => Weather Observation Locations
            [key] => code
            [label] => label
            [sortorder] => listorder
        )

    [5] => Array
        (
            [description] => Surface Snow Conditions
            [key] => code
            [label] => label
            [sortorder] => listorder
        )

    [6] => Array
        (
            [description] => Ground Snow Conditions
            [key] => code
            [label] => label
            [sortorder] => listorder
        )

    [7] => Array
        (
            [description] => Sky Conditions
            [key] => code
            [label] => label
            [sortorder] => listorder
        )

    [8] => Array
        (
            [description] => Pressure Trends
            [key] => code
            [label] => label
            [sortorder] => listorder
        )

    [9] => Array
        (
            [description] => Precipitation Type
            [key] => code
            [label] => label
            [sortorder] => listorder
        )

    [10] => Array
        (
            [description] => Snow Precipitation Rate
            [key] => code
            [label] => label
            [sortorder] => listorder
        )

    [11] => Array
        (
            [description] => Rain Precipitation Rate
            [key] => code
            [label] => label
            [sortorder] => listorder
        )

    [12] => Array
        (
            [description] => Precipitation Rates
            [key] => code
            [label] => label
            [sortorder] => listorder
        )

    [13] => Array
        (
            [description] => Air Temperature Trends
            [key] => code
            [label] => label
            [sortorder] => listorder
        )

    [14] => Array
        (
            [description] => Observed Seasons
            [key] => season_id
            [label] => season_text
            [sortorder] => season_text
        )

    [15] => Array
        (
            [description] => Avalanche Types
            [key] => code
            [label] => label
            [sortorder] => listorder
        )

    [16] => Array
        (
            [description] => Boolean Data
            [key] => code
            [label] => label
            [sortorder] => listorder
        )

    [17] => Array
        (
            [description] => Avalanche Trigger Types
            [key] => code
            [label] => label
            [sortorder] => listorder
        )

    [18] => Array
        (
            [description] => Human Modified Triggers
            [key] => code
            [label] => label
            [sortorder] => listorder
        )

    [19] => Array
        (
            [description] => Avalanche Trigger Types
            [key] => code
            [label] => code,label
            [sortorder] => code
        )

    [20] => Array
        (
            [description] => Avalanche Terminus Moisture
            [key] => code
            [label] => label
            [sortorder] => listorder
        )

    [21] => Array
        (
            [description] => Short Avalanche Debris
            [key] => code
            [label] => code,label
            [sortorder] => listorder
        )

    [22] => Array
        (
            [description] => Long Avalanche Debris
            [key] => code
            [label] => code,label
            [sortorder] => listorder
        )

    [23] => Array
        (
            [description] => Avalanche Debris (Detailed)
            [key] => code
            [label] => code,label
            [sortorder] => listorder
        )

    [24] => Array
        (
            [description] => Start Zone Vertical Measure
            [key] => code
            [label] => code,label
            [sortorder] => listorder
        )

    [25] => Array
        (
            [description] => Start Zone Horizontal Measure
            [key] => code
            [label] => code,label
            [sortorder] => listorder
        )

    [26] => Array
        (
            [description] => Avalanche Relative Path Size
            [key] => code
            [label] => label
            [sortorder] => listorder
        )

    [27] => Array
        (
            [description] => Avalanche Destructive Force
            [key] => code
            [label] => code,label
            [sortorder] => listorder
        )

    [28] => Array
        (
            [description] => Avalanche Paths
            [key] => code
            [label] => label
            [sortorder] => listorder
        )

    [29] => Array
        (
            [description] => Avalanche Bed Surface Type
            [key] => code
            [label] => code,label
            [sortorder] => listorder
        )

    [30] => Array
        (
            [description] => Estimated Wind Speeds
            [key] => code
            [label] => label
            [sortorder] => listorder
        )

)
stderr
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 62
PHP Notice:  Undefined index: name in /home/5b1vm8/prog.php on line 63