如果语句只有条件变量

Adr*_*ian 2 php

好的,只是一个简单的问题..

我不知道它是什么......有人可以解释一下是什么意思

if($var) { ... }
Run Code Online (Sandbox Code Playgroud)

我们在这里检查的是什么?

是的,还有另一个案例:

if (!$var) { ... }
Run Code Online (Sandbox Code Playgroud)

TNX!:)

sam*_*ayo 9

它只是检查变量的值.它应该返回它,只是一个布尔值.即.TRUEFALSE.

在您的情况下,(任何情况下)它被解释如下.

if($var){
  // means, if $var is set to true, or has any value at all,
   // execute the code that goes inside here.
  } 


if (!$var){
     // is the opposite of the first example, it means, 
     // if $var is set to false, or is empty, not set.. executing this code... 
   } 
Run Code Online (Sandbox Code Playgroud)

下面的示例来自PHP手册,并将向您展示在评估布尔结果时,某些表达式在PHP中的结果.

<?php
var_dump((bool) "");        // bool(false)
var_dump((bool) 1);         // bool(true)
var_dump((bool) -2);        // bool(true)
var_dump((bool) "foo");     // bool(true)
var_dump((bool) 2.3e5);     // bool(true)
var_dump((bool) array(12)); // bool(true)
var_dump((bool) array());   // bool(false)
var_dump((bool) "false");   // bool(true)
Run Code Online (Sandbox Code Playgroud)