📖 generic · 12th TN - English Medium · COMPUTER APPLICATION · Page 114question

Conditional Statements in PHP

Chapter 6: Chapter 6 · COMPUTER APPLICATION

Conditional Statements in PHP LEARNING OBJECTIVES To understand the importance of Conditional Statements To know different types of Conditional Statements in PHP Chapter Conditional Statements in PHP version CHAPTER version CHAPTER - - - - Syntax : if (condition) { // code to be executed if condition is true; } Example : <?php $x = ; if ($x > ) { echo “x is greater than ”; } ?> In this example, the condition is $x > , which is true because the value of $x is , which is greater than . Therefore, the code inside the curly braces (echo “x is greater than ”;) will be executed, and the string “x is greater than ” will be output. It’s important to note that the code inside the curly braces will only be executed if the condition is true. If the condition is false, the code will be skipped.

. . if ... else statement The if ...

else statement is a conditional statement in PHP. It executes one block of code if a condition is true and another block of code if the condition is false. Syntax if (condition) { // True-block; } else { // False-block; } If the condition is True then the True-block is executed and if the condition is False then the False- block is executed. Chapter Conditional Statements in PHP version CHAPTER version CHAPTER - - - - Example : <?php $x = ; if ($x > ) { echo “x is greater than ”; } else { echo “x is not greater than ”; } ?> Output x is greater than .

. ‘if... elseif ...else’ Statement The if ... elseif ...

else statement is a conditional statement in PHP. This statement allows you to check multiple conditions and run different code based on which condition is true. This type of statement begins with the keyword ‘ if ’. It can be followed by one or more ‘ elseif ’.

Finally ends with an ‘ else ’

Related topics

Have a question about this topic?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →