php programming in the form of assignment (condition) {statement} else {statement}
before we enter the example program I will explain what it is (condition) {statment} else {statment}
Understanding If Else in PHP (and Elseif)
On this occasion we will study and discuss about one of the control flows, namely if else in PHP, the discussion includes the if, else and elseif statements, along with examples and writing structure.
I. IF Else in PHP
As in the literal translation, if means if, then, if the condition evaluated is TRUE, then the if statement block will be executed, otherwise the ELSE statement that will be executed
If described in a flow chart, the if else logic flow in PHP or other programming languages is as follows:
If Else in PHP and Elseif - Flowchart
II. Writing Structure If Else In PHP
The writing structure of if else in php can be divided into 3, i.e.
Using kurawa brackets: if (expression) {statement}
Using colon: if (expression) endif statement
Do not use both: if (expression) statement
and I will explain its function too
The IF, ELSE and ELSEIF functions in PHP
the IF, ELSE and ELSEIF functions in PHP. This function is included in the structure control which is a branching structure. ifelsestatements [1] Branching function is the process of transferring programs to execute other program blocks, based on checking a condition / expression.
IF function
This function is very important for all programming languages, including PHP. if serves to run a function segment based on checking certain conditions through logical operators. Writing this function has 2 ways of writing. The syntax is as follows:
Method 1
if ($ expression)
$ statement carried out
Method 2
if ($ expression)
{
$ statement carried out
}
The first way of writing is more concise, but it has difficulty when we read the overall program structure, while the second method is easier to understand when we check the error program because there are {cloud and end} blocks as limits of the if function.
$ expression shows the process condition, where $ the expression must always be true or TRUE or 1. So, in this function, the statement on that block will always be executed. while block $ statement is an execution command that must be done.
and I will explain its function too
The IF, ELSE and ELSEIF functions in PHP
the IF, ELSE and ELSEIF functions in PHP. This function is included in the structure control which is a branching structure. ifelsestatements [1] Branching function is the process of transferring programs to execute other program blocks, based on checking a condition / expression.
IF function
This function is very important for all programming languages, including PHP. if serves to run a function segment based on checking certain conditions through logical operators. Writing this function has 2 ways of writing. The syntax is as follows:
Method 1
if ($ expression)
$ statement carried out
Method 2
if ($ expression)
{
$ statement carried out
}
The first way of writing is more concise, but it has difficulty when we read the overall program structure, while the second method is easier to understand when we check the error program because there are {cloud and end} blocks as limits of the if function.
$ expression shows the process condition, where $ the expression must always be true or TRUE or 1. So, in this function, the statement on that block will always be executed. while block $ statement is an execution command that must be done.
SAMPLE PROGRAM
SAMPLE PROGRAM
SAMPLE PROGRAM
SAMPLE PROGRAM
and the results will be as shown below





No comments:
Post a Comment