Given the following code snippet:
$i= 11;
function get_num() {
global $i;
return (--$i >= 0) ? $i : false;
}
while($num = get_num()) {
echo "Number: $num\n";
}
Results in the following output:
Number: 10
Number: 9
Number: 8
Number: 7
Number: 6
Number: 5
Number: 4
Number: 3
Number: 2
Number: 1
However, I also want it to output Number: 0
- but the while loop evaluates 0
as being false
, so the loop never gets to that point. How do I get the loop to terminate only on an explicit false
?