- range: documentation ( source)
<?php
function d6() { return range(1,6); }
$t = $i = 0;
foreach(d6() as $a) {
foreach(d6() as $b) {
foreach(d6() as $c) {
$t++;
if($a==$b || $a == $c || $b == $c) {
$i++;
}
}
}
}
echo "$i doubles out of $t results.\n";