[ create a new paste ] login | about

Link: http://codepad.org/DQ6viXBQ    [ raw code | output | fork ]

PHP, pasted on May 17:
<?php
$array = Array(
  9 => Array(
            15.00 => 3.0,
            20.00 => 8.0,
            25.00 => 10.5
  ),
  2 => Array(
            15.00 => 2.0,
            20.00 => 5.0,
            25.00 => 2.5
  ),
  4 => Array(
            15.00 => 6.0,
            25.00 => 4.0,
            30.00 => 6.0
  )
);

function my_func($a, $b) {
   if ($a[15.00] == $b[15.00])
      return 0;
   return ($a[15.00] < $b[15.00]) ? 1 : -1; // backwards sorting
}

uasort($array, my_func);
var_dump($array);
?>


Output:
array(3) {
  [4]=>
  array(3) {
    [15]=>
    float(6)
    [25]=>
    float(4)
    [30]=>
    float(6)
  }
  [9]=>
  array(3) {
    [15]=>
    float(3)
    [20]=>
    float(8)
    [25]=>
    float(10.5)
  }
  [2]=>
  array(3) {
    [15]=>
    float(2)
    [20]=>
    float(5)
    [25]=>
    float(2.5)
  }
}


Create a new paste based on this one


Comments: