fork download
  1. <?php
  2.  
  3. $winners = range(1, 100); // scaleable winners of /r/aww contest
  4.  
  5. $winners = array_combine($winners, $winners);//match keys to values
  6.  
  7. $mywinner = array_rand($winners); // randomly select my Dog's winning spot
  8.  
  9. echo $mywinner . '<br>'; // check my Dog's winning place to verify it's not being echoed below; comment this line upon completion
  10. unset($winners[$mywinner]); // remove my Dog from list of other winners
  11. // print out all winners except my dog
  12. foreach ($winners as $place){ // run foreach loops on every winner to attach suffix
  13. switch ($place){ //use switch to set what suffix to attach to winner's place
  14. case 11: // make sure 11th place gets th suffix, not st
  15. $place .= "th";
  16. break;
  17. case 12:// make sure 12th place gets th suffix, not nd
  18. $place .= "th";
  19. break;
  20. case 13:// make sure 13th place gets th suffix, not 3rd
  21. $place .= "th";
  22. break;
  23. case substr($place, -1) == 1: // check places ending in 1 at append 'st' suffix
  24. $place .= "st";
  25. break;
  26. case substr($place, -1) == 2:// check places ending in 2 at append 'nd' suffix
  27. $place .= "nd";
  28. break;
  29. case substr($place, -1) == 3:// check places ending in 3 at append 'rd' suffix
  30. $place .= "rd";
  31. break;
  32. default: // default suffix for every other place
  33. $place .= "th";
  34. break;
  35. }
  36.  
  37. $out[]=$place;// echo as format "1st, 2nd, 3rd, 4th, (etc to end), 100th." end with period (need fixing)
  38.  
  39. }
  40.  
  41. echo implode(', ',$out).'.';
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
93<br>1st, 2nd, 3rd, 4th, 5th, 6th, 7th, 8th, 9th, 10th, 11th, 12th, 13th, 14th, 15th, 16th, 17th, 18th, 19th, 20th, 21st, 22nd, 23rd, 24th, 25th, 26th, 27th, 28th, 29th, 30th, 31st, 32nd, 33rd, 34th, 35th, 36th, 37th, 38th, 39th, 40th, 41st, 42nd, 43rd, 44th, 45th, 46th, 47th, 48th, 49th, 50th, 51st, 52nd, 53rd, 54th, 55th, 56th, 57th, 58th, 59th, 60th, 61st, 62nd, 63rd, 64th, 65th, 66th, 67th, 68th, 69th, 70th, 71st, 72nd, 73rd, 74th, 75th, 76th, 77th, 78th, 79th, 80th, 81st, 82nd, 83rd, 84th, 85th, 86th, 87th, 88th, 89th, 90th, 91st, 92nd, 94th, 95th, 96th, 97th, 98th, 99th, 100th.