Table of Contents

    Mastering the if Statement in PHP: A Complete Guide

    Mastering the if Statement in PHP: A Complete Guide

    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