mercredi 29 juillet 2015

How to make an if statement ignore a var if 0?

I want to check if a variable is greater than x, unless it is 0.

so for example.

<?php
$max_n=10;//user setting maximum number of loops, infinite? choose 0.


//the problem is that 0 is the smallest number, so the loop stops immediately

for ($x = 0; $x <= $max_n; $x++) {
    $total_n=$x;
}

//if total number exceeds max amount of numbers, do something
if(1==1 || $total_n > $max_n )
{
    die('Total number is greater than max numbers!');
}

?>

Obviously infinite loops are a bad idea, but that is not the point.

How do I make the if statement ignore the max_n if max_n =0

Aucun commentaire:

Enregistrer un commentaire