This question already has an answer here:
I suspect the answer to this is incredibly simple and I am bracing myself for a down vote, however, having read this about changing values, trying to implement array_replace() and trying out the 'passing by reference' I have have not solved my simple problem.
$levelState
is a 16 item array populated via array_push with either a string 'locked' or 'unlocked', which may print something like this:
Array ( [0] => unlocked [1] => unlocked [2] => locked [3] => locked [4] => locked [5] => locked [6] => locked [7] => locked [8] => locked [9] => locked [10] => locked [11] => unlocked [12] => unlocked [13] => unlocked [14] => unlocked [15] => unlocked )
Under certain circumstance levels below a certain level should be unlocked.
//Function to unlock lower levels if, manually passed.
function unlockLowerLevels($x) {
while($x > 0) {
$levelState[$x] = 'unlocked';
echo $x;
$x--;
}
}
unlockLowerLevels($int);
This function does not make any change to array elements, but does echo a countdown. I would appreciate any help. Thanks.
</div>