Site icon TestingDocs.com

PHP If Statement

Overview

We can use PHP If Statement to execute code statements based on condition(s). This statement is also called a conditional statement. We can make decisions and execute code only when the conditions are met.

Syntax

Let’s see a simple syntax of the statement.

if(condition)
{
// PHP Statements;
}

The PHP code in the if block will be executed when the condition is met i.e evaluates to true.

Example


<!DOCTYPE html>
<!–
PHP If Statement Demo
–>
<html>
<head>
<meta charset=”UTF-8″>
<title>PHP If Block</title>
</head>
<body>
<h1> PHP If Block </h1>
<?php
//PHP If Block
$a = 120;
$b = 30;
if($a > $b)
{
//This block will execute only if a > b
echo “a= $a”;echo “<br/>”;
echo “b= $b”;echo “<br/>”;
echo “a is greater than b”;
}
?>
<br/>
<h1>PHP Tutorials </h1>
<h3>www.TestingDocs.com</h3>
</body>
</html>


 

PHP Tutorials

PHP Tutorials on this website:

https://www.testingdocs.com/php-tutorials/

More Information on PHP

https://www.php.net/

Exit mobile version