- max: documentation ( source)
- rand: documentation ( source)
<?php
$maxMatches = 3;
$matches = array('tails' => 0, 'heads' => 0, 'total' => 0);
while(max($matches['tails'], $matches['heads']) < $maxMatches) {
$faceType = rand(0, 1);
if ($faceType) {
$matches['heads']++;
$matches['tails'] = 0;
echo $faceType . " is heads\n";
}
else {
$matches['tails']++;
$matches['heads'] = 0;
echo $faceType." is tails\n";
}
$matches['total']++;
}
echo "total flips took is: " . $matches['total'];