use of if in php

IfExample.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>use of if in php</title>
</head>

<body>
 <h2 style="color:orange; text-align:left;">use of if in php example</h2>
 <br />
 <?php
  /*
  |---------------------------------------------------------
  | if(true/false)
  | 1 == true and 0 == false
  |---------------------------------------------------------
  */
  $variable = true;
  if($variable == true) echo "It is true<br>";
  if($variable) echo "It is true<br>";
  if($variable != false) echo "It is true<br>";
  
  $variable = false;
  if($variable == false) echo "It is false<br>";
  if($variable != true) echo "It is false<br>";
  if(!$variable) echo "It is false<br>";
  
  $variable = 123;
  if($variable) echo "It is true<br>";
  
  $variable = 0;
  if($variable) echo "It is true<br>";
  else echo "It is false<br>";
  
  $variable = -5;
  if($variable) echo "It is true<br>";
  /*
  |-----------------------------------------------------------
  | -5 is negative but still it's true
  | 0 means false
  |-----------------------------------------------------------
  */
 ?>
 
</body>
</html>

No comments:

Post a Comment

leave your comments here..