Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

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; } //print_r($roll); 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;
Copy Clear