i
PHP Variables
PHP Data Types
PHP Echo & Print
PHP Strings
PHP Numbers
PHP Constants
PHP Operators
PHP if...else...elseif Statements
Switch Statement
PHP Loops
PHP Arrays
Superglobals
PHP Coding Standards
PHP Form Handling
PHP Form Validation
PHP URLs Validation
PHP Form Required Validation
Complete Form Example
PHP File Functions Open/Read
PHP File Create/Write
PHP File Upload
PHP Cookies Handling
PHP Session Handling
PHP filter_var() Function
PHP Validation Filters
PHP Sanitization Filters
Using Filters
Filters Advanced
JSON
PHP Date and Time
MySQL Database
MySQL Connect
MySQL Commands-Creating a Table
MySQL Commands-Inserting The data
MySQL Commands-Prepared Statement
MySQL Commands-Selecting The Data
MySQL Commands-Where and Order By
MySQL Commands-Deleting And Updating The Data
PHP-OOP Introduction
PHP-Classes/Objects
PHP-Constructor/Destructor
PHP-Access Modifiers
PHP-Inheritance
PHP-Inheritance and Protected Access Modifier
PHP-Overriding Inherited Methods
PHP-Final keyword
PHP-Abstract Classes
PHP-Constants
PHP-Traits
PHP-Static Methods and Properties
Introduction to Functions
Defining A function
Returning Values From A Function
Dynamic Function Calls
Variable Scope
Understanding Arguments Or Parameters
Testing For A Function Existence
Returning Multiple Values From A Function
Making practical Use By Building Code Libraries For Code Re-usability
Using Include() And Require()
If, else and else if are decision making statements that help us to perform actions based on various conditions. In Php, we have below conditional statements.
>If statement
If statement is used when we want to execute the code if a single condition is true. Syntax of if statement is
if(condition)
{code to be executed}
For example, if you want to know a person is adult or not, you can write the below php code.
$age = 20
if($age >18)
{
echo “The person is adult”;
}
?>
>If..else statement
If..else statement helps us in a situation where we have a condition, and we want to execute the code if the condition is true and execute another code if the condition is false.
Syntax of If..else statement is as below.
if(condition)
{ code executed if the condition is true}
else
{code executed if the condition is false}
For example, To know the person is child or adult to decide some fare you can write the below php code.
$age = 15
if($age>18)
{
echo “Issue Adult fare”;
}
else
{
echo “Issue Child fare”;
}
?>
>If..elseif..else statement
If..elseif..else statement is used when you have more than two conditions to decide a code to be executed. The if code executes if condition one is true, elseif code is executed if the second condition is true and if all the conditions are false, then else code is executed. The syntax for If..elseif..else statement is as below.
if (condition)
{code executed if this condition is true;}
elseif (condition)
{code executed when first condition is false, and the specified condition is true;}
else
{code to be executed when all conditions are false;}
For example, in the before case only now you want to issue fare based on child, adults and senior citizen then you can write the below code.
$age = 15
if($age<18)
{
echo “Issue Child fare”;
}
elseif($age>18 and $age<60)
{
echo “Issue Adult fare”;
}
else
{
echo “Issue Senior Citizen fare”;
}
?>
Don't miss out!