How many types of statements are there in php?
Any PHP script is built out of a series of statements. A statement can be an assignment, a function call, a loop, a conditional statement or even a statement that does nothing (an empty statement). Statements usually end with a semicolon. In addition, statements can be grouped into a statement-group by encapsulating a group of statements with curly braces. A statement-group is a statement by itself as well. The various statement types are described in this chapter. Show
See AlsoThe following are also considered language constructs even though they are referenced under functions in the manual.
There are no user contributed notes for this page. Conditional statements are used to perform different actions based on different conditions. PHP Conditional StatementsVery often when you write code, you want to perform different actions for different conditions. You can use conditional statements in your code to do this. In PHP we have the following conditional statements:
PHP - The if StatementThe Syntax if (condition) { ExampleOutput "Have a good day!" if the current time (HOUR) is less than 20: $t = date("H"); if ($t < "20") { Try it Yourself » PHP - The if...else StatementThe Syntax
if (condition) { ExampleOutput "Have a good day!" if the current time is less than 20, and "Have a good night!" otherwise: $t = date("H"); if ($t < "20") { Try it Yourself » PHP - The if...elseif...else StatementThe Syntax if (condition) { ExampleOutput "Have a good morning!" if the current time is less than 10, and "Have a good day!" if the current time is less than 20. Otherwise it will output "Have a good night!": $t = date("H"); if ($t < "10") { Try it Yourself » PHP - The switch StatementThe PHP ExercisesWhen the program has conditions then statements are used. There are the following types of statements.
if statementwhen the program has only one condition and related statement then if statement is used.
if-else statementwhen the program, has only one condition and related two statement then the if-else statement is used.
if-else-if statementwhen the program has multiple conditions and related statements if-else-if statement is used.
Nested if statementwhen the program has a condition within other condition, there we use nested if statement.
Switch StatementIt is an alternative statement of if-else if statement there is little difference is that relational, logical operators can not be used here.
Conditional operatorsIt is an alternative to the if-else statement, and it is an inline conditional statement.
Author/Written by: Mr Hemant Singh (Founder)How many conditional statements are there in PHP?In PHP, there are 4 different types of Conditional Statements.
What does statement mean in PHP?A statement can be an assignment, a function call, a loop, a conditional statement or even a statement that does nothing (an empty statement). Statements usually end with a semicolon. In addition, statements can be grouped into a statement-group by encapsulating a group of statements with curly braces.
What are compound statements in PHP?A compound statement allows a group of zero or more statements to be treated syntactically as a single statement. A compound statement is often referred to as a block.
Why conditional statements are used in PHP?PHP allows you to choose what action to take based on the result of a condition. This condition can be anything you choose, and you can combine conditions to make actions that are more complicated.
|