if Statement in PHP

Rumman Ansari   Software Engineer   2022-09-08   5415 Share
☰ Table of Contents

Table of Content:


The if statement is used to execute a block of code only if the specified condition evaluates to true. This is the simplest PHP's conditional statements and can be written like:

Syntax:



if (condition) {
    code to be executed if condition is true;
}


Example:



<?php

$n = 12;
if($n > 0) {
 printf("n is positive");
}

?>


Output:

If you will rum the above code, you will get the following output.



n is positive