PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php $dicesCombinations = [ "Nothing" => [1, 1, 1, 1, 1], "Pair" => [1, 1, 1, 2], "Two pairs" => [1, 2, 2], "Three-of-a-Kind" => [1, 1, 3] ]; function rollDice() { $roll = []; for ($i = 0; $i <= 4; $i++) { $value = rand(1, 6); $roll[] = $value; } return $roll; } $result = rollDice(); print_r($result); sort($result); print_r($result); $checkArray = array_count_values($result); sort($checkArray); print_r($checkArray); $returnRollResult = match ($checkArray) { $dicesCombinations["Nothing"] => "Nothing", $dicesCombinations["Pair"] => "Pair", $dicesCombinations["Two pairs"] => "Two pairs", $dicesCombinations["Three-of-a-Kind"] => "Three-of-a-Kind", default => "No matches", }; echo $returnRollResult;
Show:  
Copy Clear