Summary: in this tutorial, you’ll learn about the PHP if statement and how to use it to execute a code block conditionally.
Introduction to the PHP if statement #
The if statement allows you to execute a statement if an expression evaluates to true. The following shows the syntax of the if statement:
<?php
if ( expression )
statement;Code language: PHP (php)In this syntax, PHP evaluates the expression first. If the expression evaluates to true, PHP executes the statement. In case the expression evaluates to false, PHP ignores the statement.
The following flowchart illustrates how the if statement works: