Skip to content

Instantly share code, notes, and snippets.

@yuily
Created December 28, 2014 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuily/f7c3c7e12299cc7d7873 to your computer and use it in GitHub Desktop.
Save yuily/f7c3c7e12299cc7d7873 to your computer and use it in GitHub Desktop.
phpでジャンケン 勝負数の文字列結合を数値に変換
<body>
// $player
// $rival
// $win
// $lose
$myPlayer = intval($player);
$tekiRival = intval($rival);
$win = 0;//勝ち負けは、0から加算する
$lose = 0;
for($i = 0,$j = 0;$i < count($myPlayer),$j < count($tekiRival);
$i++,$j++){ //配列の数だけループ処理
if(($myPlayer[$i] == 0)&&($tekiRival[$j] == 2)){ //変数[]で、配列の順番に基づく要素を指定。条件分岐で勝敗を加算する。
$win++;}
else if(($myPlayer[$i] == 2)&&($tekiRival[$j] == 5)){
$win++;}
else if(($myPlayer[$i] == 5)&&($tekiRival[$j] == 0)){
$win++;}
else if(($myPlayer[$i] == 0)&&($tekiRival[$j] == 5)){
$lose++;}
else if(($myPlayer[$i] == 2)&&($tekiRival[$j] == 0)){
$lose++;}
else if(($myPlayer[$i] == 5)&&($tekiRival[$j] == 2)){
$lose++;}
}
print($win.'勝'.$lose.'敗');//変数と文字列の結合
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment