Mastering the if Statement in PHP: A Complete Guide

Rumman Ansari   Software Engineer   2024-07-18 09:12:40   5422  Share
Subject Syllabus DetailsSubject Details
☰ TContent
☰Fullscreen

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