Counting output from do while loop

Hi Guys I’m basically a beginner and have been teaching myself php over the past 2 days. I am stuck on an issue that I can’t seem to get past. What I am trying to do is log the number of times a REDCARD comes up in a game I have created. I have a do while loop which runs the game five times and I would like to log the outcome total times a REDCARD appears randomly within the game over the five runs and have an echo at the end of the script to show the number of times the red card appeared. I am pretty stumped so if anyone could help it would be much appreciated!!!

[php]

<?php $i=1; do { $input=array("A" => 'Black_Ace', "B" => 'Black_King', "C" => 'Black_Queen', "D" => 'Black_Jack', "E" => 'Red_Ten'); shuffle($input); $redten = 'Red_Ten'; echo '

'; $win=$input[array_rand($input,1)]; echo 'Card Drawn'; echo '
'; echo $win; echo '
'; echo '
'; $input1=$input; unset($input1[array_search($win, $input1)]); $i++; if ($win == $redten) { echo 'If you choose to switch you have lost!!'; echo '
'; echo 'If you choose to stay you have won!!'; } else { echo 'If you choose to switch You have won!!'; echo '
'; echo 'If you choose to stay you have lost!'; } } while ($i<=5); ?>

[/php]

No thoughts on this one I take it? :-[

Just increment a variable like you are doing with $i

Sponsor our Newsletter | Privacy Policy | Terms of Service