I have a php array that's made up of random numbers from 0-100.
I'm trying to figure out the cleanest and simplest method of picking a random key from that array that is greater than zero. Ultimately I'm looping through the array, subtracting a value from random keys each loop
Pseudo code:
$num_array = array(100,50,60,40,0,30,0,20);
for ($x = 0; $x < 100; $x++) {
$rnd = RANDOM $num_array KEY WHERE > 0
$num_array[$rnd] = $num_array[$rnd] - 10;
}
Any suggestions on how to handle this?
EDIT: Once the loop is over I still want my array to contain 0's (originals, and any new ones after subtraction), and all the key positions need to be intact as before