3v4l.org

run code in 300+ PHP versions simultaneously
<?php $options = ['paper', 'rock', 'scissors']; $lookup = array_flip($options); $outcomes = ['draw', 'win', 'lose']; // only extract a random value if the player has selected an option -- otherwise there is no comparison executed. $cpuSelection = $options[array_rand($options)]; $playerSelection = 'rock'; $comparison = $lookup[$cpuSelection] - $lookup[$playerSelection]; var_export([ 'cpu' => $cpuSelection, 'human' => $playerSelection, 'outcome' => $outcomes[($comparison + 3) % 3] ]);

preferences:
27.57 ms | 402 KiB | 5 Q