SlideShare una empresa de Scribd logo
1 de 16
CONDITIONAL STATEMENT INPHP WWW.USTUDY.IN Department of CE/IT
Conditional Statement Conditional statements are the set of commands used to perform different actions based on different conditions.  In PHP we have the following conditional statements: If If else Else if switch WWW.USTUDY.IN
If statement If structure is used for conditional execution of code segment Syntax: if (expr)    {  Statements  }  WWW.USTUDY.IN
Example  <?php     if ($c > $d)        {           echo "c is bigger than d";         }  ?>     In the above example, only if the condition "$c>$d" is true, the message "c is bigger than d" is displayed WWW.USTUDY.IN
Else statement The conditional statement "else" is used as extension of "if" statement. If the condition fails then it executes another statements under the "else" condition. Syntax:      if (expr)       {           Statements          }//true        else        {           Statements         }//false  Based on the result of expressions, the statements are executed. WWW.USTUDY.IN
Example  <?php $c = 10;  $d = 20;  if ($c > $d)  { echo "C is bigger than d"; }  Else  { echo "D is bigger than c"; }  ?> WWW.USTUDY.IN
Result  Result: D is bigger than C      In the above example in the if the condition "$c>$d" is true then the message "C is bigger than D" is displayed, else the message "D is bigger than C" is displayed. WWW.USTUDY.IN
Else if statement else if statement is used as extension of "If" structure if the condition fails then it executes another "If" condition to execute the code segment under the "else if" statement WWW.USTUDY.IN
Syntax  if (expr 1)  { Statements }//true  elseif (expr2)//false  { Statements }//true  Else  { Statements }//false  Based on the failure "expr1" condition, "expr2" is checked and then the statements are executed. WWW.USTUDY.IN
Example  <?php  $c = 10;  $d = 10;  if ($c > $d)  {  echo "c is bigger than d";  } elseif ($c==$d)  {  echo "c is equal to d";  }  else  {  echo "d is smaller than c"; } ?> WWW.USTUDY.IN
Result  c is equal to d  In the above example the if the condition "$c>$d" is true then the message "c is bigger than d" is displayed, else the condition in the else if that is "$c==$d" is evaluated if it is true the message "c is equal to d" is displayed otherwise "d is smaller than c" is displayed WWW.USTUDY.IN
Switch statement The Switch case statement is used to compare a variable or expression to different values based on which a set of code is executed. WWW.USTUDY.IN
Syntax  Switch (Variable or expression)  {  Case (value 0):  { Statements }  Case (value 1):  { Statements } …………  Case (value n):  {statements }  default:  { Statements }  } WWW.USTUDY.IN
Example  <?php  $c=3;  switch ($c)  {  case 0:  echo "value of $c = 0 <br>";  break;  case 1:  echo "value of $c = 1 <br>";  break;  case 2:  echo "value of $c = 2 <br>";  break;  default:  echo "value of $c = Default value <br>";  break;  } ?> WWW.USTUDY.IN
Result  value of 3 = Default value  In the above example based on the value of $c the messages are displayed of that particular case which matches. The default case accepts anything not matched by other cases, so the value "3" displays the default message. WWW.USTUDY.IN
The End  THANK U WWW.USTUDY.IN

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Looping statement
Looping statementLooping statement
Looping statement
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
 
Introduction of java
Introduction  of javaIntroduction  of java
Introduction of java
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in java
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
 
Java threads
Java threadsJava threads
Java threads
 
Basics of Java Concurrency
Basics of Java ConcurrencyBasics of Java Concurrency
Basics of Java Concurrency
 
Java interface
Java interfaceJava interface
Java interface
 
Hibernate notes
Hibernate notesHibernate notes
Hibernate notes
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
 
Java string handling
Java string handlingJava string handling
Java string handling
 
Collections Framework
Collections FrameworkCollections Framework
Collections Framework
 
Java I/O
Java I/OJava I/O
Java I/O
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
 
Control statements in java programmng
Control statements in java programmngControl statements in java programmng
Control statements in java programmng
 
Statements and Conditions in PHP
Statements and Conditions in PHPStatements and Conditions in PHP
Statements and Conditions in PHP
 
Java Threads
Java ThreadsJava Threads
Java Threads
 
Spring JDBCTemplate
Spring JDBCTemplateSpring JDBCTemplate
Spring JDBCTemplate
 
Php string function
Php string function Php string function
Php string function
 
Inheritance and Polymorphism Java
Inheritance and Polymorphism JavaInheritance and Polymorphism Java
Inheritance and Polymorphism Java
 

Destacado

Comm1coll2 Versie Igor
Comm1coll2 Versie IgorComm1coll2 Versie Igor
Comm1coll2 Versie IgorIgor ter Halle
 
Кадеты
КадетыКадеты
Кадетыdalton1k
 
Cambridge University Press ELT Publications
Cambridge University Press ELT PublicationsCambridge University Press ELT Publications
Cambridge University Press ELT PublicationsHala Nur
 

Destacado (8)

Sheetal Rane
Sheetal RaneSheetal Rane
Sheetal Rane
 
Citi_Trends
Citi_TrendsCiti_Trends
Citi_Trends
 
Presentacion
PresentacionPresentacion
Presentacion
 
Crucigrama términos tecnológicos
Crucigrama términos tecnológicosCrucigrama términos tecnológicos
Crucigrama términos tecnológicos
 
Comm1coll2 Versie Igor
Comm1coll2 Versie IgorComm1coll2 Versie Igor
Comm1coll2 Versie Igor
 
Кадеты
КадетыКадеты
Кадеты
 
Web Analytics 101
Web Analytics 101Web Analytics 101
Web Analytics 101
 
Cambridge University Press ELT Publications
Cambridge University Press ELT PublicationsCambridge University Press ELT Publications
Cambridge University Press ELT Publications
 

Similar a Conditional statement

Similar a Conditional statement (20)

Lecture 2
Lecture 2Lecture 2
Lecture 2
 
03loop conditional statements
03loop conditional statements03loop conditional statements
03loop conditional statements
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
Php Condition Flow
Php Condition FlowPhp Condition Flow
Php Condition Flow
 
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docx
 
C Constructs (C Statements & Loop)
C Constructs (C Statements & Loop)C Constructs (C Statements & Loop)
C Constructs (C Statements & Loop)
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
 
Control All
Control AllControl All
Control All
 
Chapter 8 - Conditional Statement
Chapter 8 - Conditional StatementChapter 8 - Conditional Statement
Chapter 8 - Conditional Statement
 
C statements.ppt presentation in c language
C statements.ppt presentation in c languageC statements.ppt presentation in c language
C statements.ppt presentation in c language
 
Conditions In C# C-Sharp
Conditions In C# C-SharpConditions In C# C-Sharp
Conditions In C# C-Sharp
 
JavaScript, Missing Manual, Chapter 3
JavaScript, Missing Manual, Chapter 3JavaScript, Missing Manual, Chapter 3
JavaScript, Missing Manual, Chapter 3
 
Programming basics
Programming basicsProgramming basics
Programming basics
 
CHAPTER-3a.ppt
CHAPTER-3a.pptCHAPTER-3a.ppt
CHAPTER-3a.ppt
 
What Is Php
What Is PhpWhat Is Php
What Is Php
 
Php Operators N Controllers
Php Operators N ControllersPhp Operators N Controllers
Php Operators N Controllers
 
C language UPTU Unit3 Slides
C language UPTU Unit3 SlidesC language UPTU Unit3 Slides
C language UPTU Unit3 Slides
 
Presentation1
Presentation1Presentation1
Presentation1
 
Elements of programming
Elements of programmingElements of programming
Elements of programming
 

Más de ilakkiya

History object
History objectHistory object
History objectilakkiya
 
Twisted pair cable
Twisted pair cableTwisted pair cable
Twisted pair cableilakkiya
 
Network topology
Network topologyNetwork topology
Network topologyilakkiya
 
Looping statement in vb.net
Looping statement in vb.netLooping statement in vb.net
Looping statement in vb.netilakkiya
 
Data types in php
Data types in phpData types in php
Data types in phpilakkiya
 
Array in php
Array in phpArray in php
Array in phpilakkiya
 
Decision statements in vb.net
Decision statements in vb.netDecision statements in vb.net
Decision statements in vb.netilakkiya
 
Addressing mode
Addressing modeAddressing mode
Addressing modeilakkiya
 

Más de ilakkiya (9)

History object
History objectHistory object
History object
 
Twisted pair cable
Twisted pair cableTwisted pair cable
Twisted pair cable
 
Infrared
InfraredInfrared
Infrared
 
Network topology
Network topologyNetwork topology
Network topology
 
Looping statement in vb.net
Looping statement in vb.netLooping statement in vb.net
Looping statement in vb.net
 
Data types in php
Data types in phpData types in php
Data types in php
 
Array in php
Array in phpArray in php
Array in php
 
Decision statements in vb.net
Decision statements in vb.netDecision statements in vb.net
Decision statements in vb.net
 
Addressing mode
Addressing modeAddressing mode
Addressing mode
 

Último

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Último (20)

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 

Conditional statement

  • 1. CONDITIONAL STATEMENT INPHP WWW.USTUDY.IN Department of CE/IT
  • 2. Conditional Statement Conditional statements are the set of commands used to perform different actions based on different conditions. In PHP we have the following conditional statements: If If else Else if switch WWW.USTUDY.IN
  • 3. If statement If structure is used for conditional execution of code segment Syntax: if (expr) { Statements } WWW.USTUDY.IN
  • 4. Example <?php if ($c > $d) { echo "c is bigger than d"; } ?> In the above example, only if the condition "$c>$d" is true, the message "c is bigger than d" is displayed WWW.USTUDY.IN
  • 5. Else statement The conditional statement "else" is used as extension of "if" statement. If the condition fails then it executes another statements under the "else" condition. Syntax: if (expr) { Statements }//true else { Statements }//false Based on the result of expressions, the statements are executed. WWW.USTUDY.IN
  • 6. Example <?php $c = 10; $d = 20; if ($c > $d) { echo "C is bigger than d"; } Else { echo "D is bigger than c"; } ?> WWW.USTUDY.IN
  • 7. Result Result: D is bigger than C In the above example in the if the condition "$c>$d" is true then the message "C is bigger than D" is displayed, else the message "D is bigger than C" is displayed. WWW.USTUDY.IN
  • 8. Else if statement else if statement is used as extension of "If" structure if the condition fails then it executes another "If" condition to execute the code segment under the "else if" statement WWW.USTUDY.IN
  • 9. Syntax if (expr 1) { Statements }//true elseif (expr2)//false { Statements }//true Else { Statements }//false Based on the failure "expr1" condition, "expr2" is checked and then the statements are executed. WWW.USTUDY.IN
  • 10. Example <?php $c = 10; $d = 10; if ($c > $d) { echo "c is bigger than d"; } elseif ($c==$d) { echo "c is equal to d"; } else { echo "d is smaller than c"; } ?> WWW.USTUDY.IN
  • 11. Result c is equal to d In the above example the if the condition "$c>$d" is true then the message "c is bigger than d" is displayed, else the condition in the else if that is "$c==$d" is evaluated if it is true the message "c is equal to d" is displayed otherwise "d is smaller than c" is displayed WWW.USTUDY.IN
  • 12. Switch statement The Switch case statement is used to compare a variable or expression to different values based on which a set of code is executed. WWW.USTUDY.IN
  • 13. Syntax Switch (Variable or expression) { Case (value 0): { Statements } Case (value 1): { Statements } ………… Case (value n): {statements } default: { Statements } } WWW.USTUDY.IN
  • 14. Example <?php $c=3; switch ($c) { case 0: echo "value of $c = 0 <br>"; break; case 1: echo "value of $c = 1 <br>"; break; case 2: echo "value of $c = 2 <br>"; break; default: echo "value of $c = Default value <br>"; break; } ?> WWW.USTUDY.IN
  • 15. Result value of 3 = Default value In the above example based on the value of $c the messages are displayed of that particular case which matches. The default case accepts anything not matched by other cases, so the value "3" displays the default message. WWW.USTUDY.IN
  • 16. The End THANK U WWW.USTUDY.IN