Need help with PHP self playing rock paper scissors, if else statement doesnt work

php

#1



Player 1


<?php
$playerthrow=array("rock","paper","scissors");
$rand_keys = array_rand($playerthrow, 2);
echo $playerthrow[$rand_keys[0]] . "";
    
    
    echo "<p>Player 2</p>";

$computerthrow=array("rock","paper","scissors");
$rand_keys1 = array_rand($computerthrow, 2);
echo $computerthrow[$rand_keys1[0]] . "";

$rand_keys = "";
$rand_keys1 = "";

$randomcomp = rand(1,3);

echo "

";

if ($rand_keys1 == "rock" && $rand_keys == "rock") {
echo 'Draw';
}

else if ($rand_keys1 == "paper" && $rand_keys== "paper") {
echo 'Draw';
}

else if ($rand_keys1 == "scissors" && $rand_keys == "scissors") {
echo 'Draw';
}

else if ($rand_keys1 == "rock" && $rand_keys == "paper") {
echo 'Win';
}

else if ($rand_keys1 == "paper" && $rand_keys == "scissors") {
echo 'Win';
}

else if ($rand_keys1 == "scissors" && $rand_keys == "rock") {
echo 'Win';
}

else if ($rand_keys1 == "scissors" && $rand_keys == "paper") {
echo 'loss';
}

else if ($rand_keys1 == "paper" && $rand_keys == "rock") {
echo 'loss';
}

else if ($rand_keys1 == "rock" && $rand_keys == "scissors") {
echo 'loss';
}

?>


#2

Does this not select two items?


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.