PHP / Conditional StatementsConditional statements in PHP are of 4 types 1. if statement. 2. if...else statement. 3. if...elseif...else statement. 4. Switch statement. if Statement It executes a block/ line/ lines of code if the condition is true. Syntax if (condition) { Executes block/ line/ lines of code if one condition is true. }
if...else Statement in PHP The if...else statement executes some code if a condition is true and another code if that condition is false. Syntax if (condition) { Executes block/ line/ lines of code if one condition is true. } else { Executes block/ line/ lines of code if one condition is true. }
if...elseif...else Statement in PHP It is used to execute different codes for more than 2 conditions. Syntax if (condition) { code to be executed if this condition is true; } elseif (condition) { code to be executed if first condition is false and this condition is true; } else { code to be executed if all conditions are false; }
PHP Switch Statement Use the switch statement to select one of many blocks of code to be executed. It codition matches with the case value it will execute the corresponding block. Syntax
|