Coin Toss


Just a question: $flip = rand(0,1); does the 0 = Heads? Not sure how we get heads or tails? I mean I can see we get it from $flip = rand(0,1) but which one is H and which one is T?

<p>We will keep flipping a coin as long as the result is heads!</p>
	$flipCount = 0;
	do {
		$flip = rand(0,1);
		$flipCount ++;
		if ($flip){
			echo "<div class=\"coin\">H</div>";
		else {
			echo "<div class=\"coin\">T</div>";
	} while ($flip);
	$verb = "were";
	$last = "flips";
	if ($flipCount == 1) {
		$verb = "was";
		$last = "flip";
	echo "<p>There {$verb} {$flipCount} {$last}!</p>";


here $flip means true
and true is always 1

how to check-----
just add echo $flip;

if ($flip){
echo $flip;
echo "<div class=\"coin\">H</div>";