fork download
  1. <?php
  2. $arr = [
  3. ['result'=>['name'=>'WIN']],
  4. ['result'=>['name'=>'LOSE']],
  5. ['result'=>['name'=>'WIN']],
  6. ['result'=>[]],
  7. ['result'=>['name'=>'UNKO']],
  8. ['result'=>['name'=>'EVEN']]
  9. ];
  10. $len = count($arr);
  11. $res = ['WIN' => 0, 'LOSE' => 0, 'EVEN' => 0, 'ERROR' => 0];
  12. for ($i = 0; $i < $len; $i++) {
  13. $name = isset($arr[$i]['result']['name']) ? $arr[$i]['result']['name'] : 'ERROR';
  14. switch ($name) {
  15. case "WIN":
  16. case "LOSE":
  17. case "EVEN":
  18. $res[$name]++;
  19. break;
  20. default:
  21. $res['ERROR']++;
  22. }
  23. }
  24. $len -= $res['ERROR'];
  25. echo "勝ち:{$res['WIN']}/{$len} (".round($res['WIN']/$len*100, 2)."%)<br>\n",
  26. "負け:{$res['LOSE']}/{$len} (".round($res['LOSE']/$len*100, 2)."%)<br>\n",
  27. "引き分け:{$res['EVEN']}/{$len} (".round($res['EVEN']/$len*100, 2)."%)<br>\n";
Success #stdin #stdout 0s 82880KB
stdin
Standard input is empty
stdout
勝ち:2/4 (50%)<br>
負け:1/4 (25%)<br>
引き分け:1/4 (25%)<br>