fork download
  1. <?php
  2.  
  3.  
  4. $jsonArray = json_decode($json, true);
  5.  
  6. function returnJson($jsonArray) {
  7. $totalScore1 = [];
  8. $totalScore2 = [];
  9. $totalScore3 = [];
  10. $totalScore4 = [];
  11. $totalScore5 = [];
  12.  
  13. foreach ($jsonArray as $value){
  14.  
  15. if ($value["type"] == "yyy") {
  16. $number = $value["user"];
  17. $score = $value['score'];
  18.  
  19. switch($number){
  20. case 0:
  21. array_push($totalScore1, ["_id" => $value["_id"], "score" => $score, "user" => $number, "type" => $value["type"]]);
  22.  
  23. break;
  24. case 1:
  25. array_push($totalScore2, $score);
  26.  
  27. break;
  28. case 2:
  29. array_push($totalScore3, $score);
  30.  
  31. break;
  32. case 3:
  33. array_push($totalScore4, $score);
  34.  
  35. break;
  36. case 4:
  37. array_push($totalScore5, $score);
  38.  
  39. break;
  40. }
  41. }
  42. }
  43. $result = checkArray($totalScore1);
  44.  
  45. //var_dump($totalScore1[1]);
  46. }
  47. function checkArray($totalScore){
  48.  
  49.  
  50.  
  51. for($i = 0; $i <= count($totalScore); $i ++){
  52.  
  53. $result = array_intersect($totalScore[$i], $totalScore[$i+1]);
  54. if(!empty($result)){
  55. unset($totalScore[$i]);
  56. }
  57. }
  58. var_dump($totalScore);
  59.  
  60.  
  61.  
  62. $totalScoreUnique = array_unique($totalScore);
  63.  
  64. if(count($totalScoreUnique) > 1){
  65.  
  66. $min = min($totalScoreUnique);
  67. unset($totalScoreUnique[array_search($min, $totalScoreUnique)]);
  68. return $totalScoreUnique;
  69. }
  70. return $totalScoreUnique;
  71. }
  72.  
  73.  
  74. returnJson($jsonArray);
  75.  
  76.  
Success #stdin #stdout #stderr 0.02s 52472KB
stdin
Standard input is empty
stdout
array(0) {
}
stderr
PHP Notice:  Undefined variable: json in /home/SwcJCY/prog.php on line 4
PHP Warning:  Invalid argument supplied for foreach() in /home/SwcJCY/prog.php on line 13
PHP Notice:  Undefined offset: 0 in /home/SwcJCY/prog.php on line 53
PHP Notice:  Undefined offset: 1 in /home/SwcJCY/prog.php on line 53
PHP Warning:  array_intersect(): Argument #1 is not an array in /home/SwcJCY/prog.php on line 53