Regarding if statements in PHP

后端 未结 6 1959
轮回少年
轮回少年 2020-12-06 22:31

I\'ve seen some PHP statements that go something like

 if($variable) {} or
 if(function()) {} (if statements that don\'t compare two variables)
6条回答
  •  春和景丽
    2020-12-06 23:01

    something that may help. You are probably thinking of something like if ($variable < 10), or if ($variable == 'some value'). Just like +, -, /, *, and % these are operators. 1 + 3 returns a value of 4 which is used in the rest of a standard statement. 1 < 3 returns a value of false which is used in the rest of the statement. the if-method accepts a boolean parameter, and executes code if that boolean parameter is true.

    notice that:

    if (1 < 3) { ... }
    

    is the same as

    $myComparison = 1 < 3;
    if ($myComparison) { ... }
    

提交回复
热议问题