SlideShare a Scribd company logo
1 of 8
Read More at: https://programing-code-example.blogspot.com
Three decision making statements
in PHP
If, elseif and switch statement are used for making
decision based on different situations.
1. If…else statement:- If one condition is true and
other is false then this statement is used.
2. Elseif statement:- If there are more than one
condition true this statement can be used.
3. Switch statement:- This statement is used to select
one block of code to execute out of many blocks. This
is beneficial to avoid long blocks of if…else, elseif
codes.
Read More at: https://programing-code-example.blogspot.com
The If...Else Statement in PHP
If one condition is true and another is false then if else
statement is used.
Below is syntax:-
If (Condition)
Code with true condition;
Else
Code with false condition;
Read More at: https://programing-code-example.blogspot.com
ElseIf Statement in PHP
If there is a posibilities that several condition is true,
then use elseif statement. Below is syntax for elseif
statement in PHP:-
if (condition)
Code1 with posible true condition;
elseif (condition)
Code2 with posible true condition;
else
code with posible true condition;
Read More at: https://programing-code-example.blogspot.com
Switch Statement in PHP
If you want execute one block of code out of many, use switch statement. The
switch statement is to avoid long block of if..elseif..else code.
Below is switch statement syntax:-
switch (expression)
{
case label1:
code to be executed if expression = label1;
break;
case label2:
code to be executed if expression = label2;
break;
default:
code to be executed
if expression is different
from both label1 and label2;
}
Read More at: https://programing-code-example.blogspot.com
More About Switch Statement in PHP
Switch statement executes line by line and once finds a
true condition it execute the corresponding block code
and all other remaining cases till the end of switch
statement. To avoid this add a break statement at the
end of each case block. The break statement tells the
php to jump out of the switch case statement once it
execute the code with first true case. If there is no
matching case then the code in default block will be
executed.
Read More at: https://programing-code-example.blogspot.com
Difference between if…else and switch case in PHP
The switch case statement is an alternative of
if…elseif…else statement. The if…elseif…else statement
also do same thing. The switch case statement finds a
suitable block of code with true case and execute that
code.
The only difference is that switch case statement is
executed line by line and once a true condition is find
not only executed that case but also execute all the
subsequent cases till the end of switch statement. To
prevent this break statement is used.
Read More at: https://programing-code-example.blogspot.com
Thank You……
Read More at: https://programing-code-example.blogspot.com

More Related Content

Similar to All about decision making statements in php

Looping statement
Looping statementLooping statement
Looping statement
ilakkiya
 

Similar to All about decision making statements in php (20)

PHP MATERIAL
PHP MATERIALPHP MATERIAL
PHP MATERIAL
 
C# conditional branching statement
C# conditional branching statementC# conditional branching statement
C# conditional branching statement
 
php
phpphp
php
 
Python decision making
Python   decision makingPython   decision making
Python decision making
 
Vb script tutorial
Vb script tutorialVb script tutorial
Vb script tutorial
 
03loop conditional statements
03loop conditional statements03loop conditional statements
03loop conditional statements
 
basics of python - control_structures_and_debugging.pptx
basics of python - control_structures_and_debugging.pptxbasics of python - control_structures_and_debugging.pptx
basics of python - control_structures_and_debugging.pptx
 
python conditional statement.pptx
python conditional statement.pptxpython conditional statement.pptx
python conditional statement.pptx
 
BSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETBSc. III Unit iii VB.NET
BSc. III Unit iii VB.NET
 
RaspberryPi & Python Workshop Day - 02.pptx
RaspberryPi & Python Workshop Day - 02.pptxRaspberryPi & Python Workshop Day - 02.pptx
RaspberryPi & Python Workshop Day - 02.pptx
 
Chapter 03 conditional statements
Chapter 03   conditional statementsChapter 03   conditional statements
Chapter 03 conditional statements
 
Looping statement
Looping statementLooping statement
Looping statement
 
Lesson 6 php if...else...elseif statements
Lesson 6   php if...else...elseif statementsLesson 6   php if...else...elseif statements
Lesson 6 php if...else...elseif statements
 
PHP-Part2
PHP-Part2PHP-Part2
PHP-Part2
 
PHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet SolutionPHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet Solution
 
Learn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & LoopsLearn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & Loops
 
Final requirement
Final requirementFinal requirement
Final requirement
 
What Is Php
What Is PhpWhat Is Php
What Is Php
 
Switch case and looping jam
Switch case and looping jamSwitch case and looping jam
Switch case and looping jam
 
Free PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in IndiaFree PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in India
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

All about decision making statements in php

  • 1. Read More at: https://programing-code-example.blogspot.com
  • 2. Three decision making statements in PHP If, elseif and switch statement are used for making decision based on different situations. 1. If…else statement:- If one condition is true and other is false then this statement is used. 2. Elseif statement:- If there are more than one condition true this statement can be used. 3. Switch statement:- This statement is used to select one block of code to execute out of many blocks. This is beneficial to avoid long blocks of if…else, elseif codes. Read More at: https://programing-code-example.blogspot.com
  • 3. The If...Else Statement in PHP If one condition is true and another is false then if else statement is used. Below is syntax:- If (Condition) Code with true condition; Else Code with false condition; Read More at: https://programing-code-example.blogspot.com
  • 4. ElseIf Statement in PHP If there is a posibilities that several condition is true, then use elseif statement. Below is syntax for elseif statement in PHP:- if (condition) Code1 with posible true condition; elseif (condition) Code2 with posible true condition; else code with posible true condition; Read More at: https://programing-code-example.blogspot.com
  • 5. Switch Statement in PHP If you want execute one block of code out of many, use switch statement. The switch statement is to avoid long block of if..elseif..else code. Below is switch statement syntax:- switch (expression) { case label1: code to be executed if expression = label1; break; case label2: code to be executed if expression = label2; break; default: code to be executed if expression is different from both label1 and label2; } Read More at: https://programing-code-example.blogspot.com
  • 6. More About Switch Statement in PHP Switch statement executes line by line and once finds a true condition it execute the corresponding block code and all other remaining cases till the end of switch statement. To avoid this add a break statement at the end of each case block. The break statement tells the php to jump out of the switch case statement once it execute the code with first true case. If there is no matching case then the code in default block will be executed. Read More at: https://programing-code-example.blogspot.com
  • 7. Difference between if…else and switch case in PHP The switch case statement is an alternative of if…elseif…else statement. The if…elseif…else statement also do same thing. The switch case statement finds a suitable block of code with true case and execute that code. The only difference is that switch case statement is executed line by line and once a true condition is find not only executed that case but also execute all the subsequent cases till the end of switch statement. To prevent this break statement is used. Read More at: https://programing-code-example.blogspot.com
  • 8. Thank You…… Read More at: https://programing-code-example.blogspot.com