Created
December 28, 2014 14:47
-
-
Save yuily/f7c3c7e12299cc7d7873 to your computer and use it in GitHub Desktop.
phpでジャンケン 勝負数の文字列結合を数値に変換
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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