fork(2) download
  1. <?php
  2. $a=array("John"=>array("test_id"=>1, "student_id"=>2, "mark"=>3),
  3. "Peter"=>array("test_id"=>1, "student_id"=>4, "mark"=>1),
  4. "Hans"=>array("test_id"=>1, "student_id"=>3, "mark"=>1),
  5. "Helen"=>array("test_id"=>2, "student_id"=>2, "mark"=>5));
  6.  
  7. $b=array_values($a);
  8.  
  9.  
  10. $c = array_keys($a);
  11.  
  12. $i = count($b);
  13. for ($j = 0; $j<$i; $j++)
  14. {
  15. if ($b[$j]['mark']>$b[$j+1]['mark'])
  16. {
  17. $max = $b[$j];
  18. $b[$j] = $b[$j+1];
  19. $b[$j+1]=$max;
  20. //_____________________________________________
  21. $max = $c[$j];
  22. $c[$j] = $c[$j+1];
  23. $c[$j+1]=$max;
  24.  
  25.  
  26.  
  27.  
  28. }
  29.  
  30.  
  31.  
  32.  
  33. }
  34. $bc = array_combine($c, $b);
  35. print_r($bc);
  36.  
  37.  
  38. // your code goes here
Success #stdin #stdout #stderr 0.02s 23568KB
stdin
Standard input is empty
stdout
Array
(
    [Peter] => Array
        (
            [test_id] => 1
            [student_id] => 4
            [mark] => 1
        )

    [Hans] => Array
        (
            [test_id] => 1
            [student_id] => 3
            [mark] => 1
        )

    [John] => Array
        (
            [test_id] => 1
            [student_id] => 2
            [mark] => 3
        )

    [] => 
    [Helen] => Array
        (
            [test_id] => 2
            [student_id] => 2
            [mark] => 5
        )

)
stderr
PHP Notice:  Undefined offset: 4 in /home/zAjfaQ/prog.php on line 15
PHP Notice:  Undefined offset: 4 in /home/zAjfaQ/prog.php on line 18
PHP Notice:  Undefined offset: 4 in /home/zAjfaQ/prog.php on line 22