<?php
$l = 4000;
function flip($h, $t)
{
if ($h + $t <= 29) {
$a = mt_rand(0, 1);
if ($a == 1) {
flip($h + 1, $t);
} else {
flip($h, $t + 1);
}
} else {
echo "$h,$t" . "</br>";
}
}
$ar = array( "test");
for ($i = 0; $i <= $l; $i++) {
array_push($ar, flip(0, 0));
}
?>
My code is supposed to give the number of tails and heads upon spinnings 30 times. And this process is done 4000 times. I want to store all the results of the 4000 times in an array using the above code. But I think the way I defined by flip is wrong. I didn't know how to store the value of the arguments of flip after it is done therefore I used an echo.
When i run this code.. for some reason it is printing out all the answers like this : http://searchr.us/testing/ip.php instead of just making an array. I have pin pointed that the way I took the vfilanl values of flip wrong. Can someone tell me the difference between echo , print and how DO i use return. When i just use return(); after echo.It gives me an error.
Please clarify my doubt on how I can output these values.