Loop problem... also need an array but can't put it in right
Posted: Tue Jul 05, 2005 12:44 am
I need some help with this script.
I want this script to run 100 times, which it does. I want it to echo out $w each time it goes by, and with the variables i've selected, it should say 5 each time and it doesn't.
After that, I need to catch $w and put it in an array. I can't seem to get anything into an array except for the first or last entry so i have removed that section of code. With the variables i have choosen, the final product should be it echoing 5, 100 time, and i have 5 100 times in an array.
I was trying array_push to add $w each time, if that will do the trick, but from what i see it won't. Please help me out with this small part of my script.
x=5
y=100000
z=5
I want this script to run 100 times, which it does. I want it to echo out $w each time it goes by, and with the variables i've selected, it should say 5 each time and it doesn't.
After that, I need to catch $w and put it in an array. I can't seem to get anything into an array except for the first or last entry so i have removed that section of code. With the variables i have choosen, the final product should be it echoing 5, 100 time, and i have 5 100 times in an array.
I was trying array_push to add $w each time, if that will do the trick, but from what i see it won't. Please help me out with this small part of my script.
x=5
y=100000
z=5
Code: Select all
<?php
$counter=0;
$maxtimes=100;
while($counter<$maxtimes)
{ $counter++;
DO {
$c = 40 * (($_POST[y]++) / $_POST[x]) ;
$num = mt_rand( 1, 100 );
If ($num <= $c) {
$w++;
$_POST[x]++;
$_POST[z]--;
$_POST[y]--;
} else {
$_POST[z]--;
$_POST[y]--;
}
} while ($_POST[z] > 0);
Echo "$w<br>";
$w=0;
}
?>Code: Select all
5
1
1
1
...