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], "Four-of-a-Kind" => [1, 4], "Five-of-a-Kind " => [5], "Full House" => [2, 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", $dicesCombinations["Four-of-a-Kind"] => "Four-of-a-Kind", $dicesCombinations["Five-of-a-Kind"] => "Five-of-a-Kind", $dicesCombinations["Full House"] => "Full House", default => "No matches", }; echo $returnRollResult;
Show:  
Copy Clear