SlideShare una empresa de Scribd logo
1 de 10
PHP Conditional Logic
The if Statement An if statement is a way of controlling the execution of a statement that follows it (that is, a single statement or a block of code inside braces). The if statement evaluates an expression between parentheses. If this expression results in a true value, the statement is executed. Otherwise, the statement is skipped entirely. This enables scripts to make decisions based on any number of factors. 	if (expression) {  	// code to execute if the expression evaluates to true  	}
Sample #1 <?php  $satisfied = "very";   if ( $satisfied == "very" ) {  echo"We are pleased that you are happy with our service";   // register customer satisfaction in some way  }  ?>
Using the else Clause with the if Statement When working with the if statement, you will often want to define an alternative block of code that should be executed if the expression you are testing evaluates to false. You can do this by adding else to the if statement followed by a further block of code, like so: 	if (expression) {  	// code to execute if the expression evaluates to true  	} else  {  	// code to execute in all other cases }
Sample #2 <?php // $satisfied = "very"; if ( $satisfied == "very" ) { echo "We are pleased that you are happy with our service";  // register customer satisfaction in some way } else {  echo "Please take a moment to rate our service"; // present pulldown }  ?>
Using the else if Clause with the if Statement You can use an if/else else/if construct to test multiple expressions before offering a default block of code: if ( expression ) {  // code to execute if the expression evaluates to true  } else if ( another expression ) {  // code to execute if the previous expression failed  // and this one evaluates to true  	} else {  	// code to execute in all other cases  	}
Sample #3 <?php $satisfied = "no";  if ( $satisfied == "very" ) {  echo "We are pleased that you are happy with our service";  // register customer satisfaction in some way  } else if ( $satisfied == "no") {  echo "We are sorry that we have not met your expectations";  // request further feedback  } else { echo "Please take a moment to rate our service";  // present pulldown } ?>
The switch Statement The switch statement is an alternative way of changing program flow according to the evaluation of an expression. . Using the if statement in conjunction with else if, you can evaluate multiple expressions. Switch evaluates only one expression, executing different code according to the result of that expression, as long as the expression evaluates to a simple type (a number, string, or Boolean).  	switch (expression) {  	case result1:  	// execute this if expression results in result1  	break;  	case result2:  	// execute this if expression results in result2  	break;  	default:  	// execute this if no break statement  	// has been encountered hitherto  	}
Sample #4 <?php $satisfied = "no";  switch ( $satisfied ) {  case "very":  echo "We are pleased that you are happy with our service";  break;  case "no“: echo "We are sorry that we have not met your expectations";  break;  default:  echo "Please take a moment to rate our service"; 21:  }  ?>
Thank You!

Más contenido relacionado

La actualidad más candente

Decision and looping examples with php (WT)
Decision and looping examples with php (WT)Decision and looping examples with php (WT)
Decision and looping examples with php (WT)kunjan shah
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__elseeShikshak
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statementRaj Parekh
 
13 javascript techniques to improve your code
13 javascript techniques to improve your code13 javascript techniques to improve your code
13 javascript techniques to improve your codeSurendra kumar
 
The secret of Functional Programming revealed!
The secret of Functional Programming revealed!The secret of Functional Programming revealed!
The secret of Functional Programming revealed!Torbjørn Marø
 
Selection statements
Selection statementsSelection statements
Selection statementsHarsh Dabas
 
nuts and bolts of c++
nuts and bolts of c++nuts and bolts of c++
nuts and bolts of c++guestfb6ada
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C pptMANJUTRIPATHI7
 

La actualidad más candente (14)

Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
Decision and looping examples with php (WT)
Decision and looping examples with php (WT)Decision and looping examples with php (WT)
Decision and looping examples with php (WT)
 
Php
PhpPhp
Php
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__else
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statement
 
Simple perl scripts
Simple perl scriptsSimple perl scripts
Simple perl scripts
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
13 javascript techniques to improve your code
13 javascript techniques to improve your code13 javascript techniques to improve your code
13 javascript techniques to improve your code
 
The secret of Functional Programming revealed!
The secret of Functional Programming revealed!The secret of Functional Programming revealed!
The secret of Functional Programming revealed!
 
Selection statements
Selection statementsSelection statements
Selection statements
 
Flow of control ppt
Flow of control pptFlow of control ppt
Flow of control ppt
 
nuts and bolts of c++
nuts and bolts of c++nuts and bolts of c++
nuts and bolts of c++
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
 
Control Statements in Matlab
Control Statements in  MatlabControl Statements in  Matlab
Control Statements in Matlab
 

Similar a Php Condition Flow (20)

What Is Php
What Is PhpWhat Is Php
What Is Php
 
Chapter 4 flow control structures and arrays
Chapter 4 flow control structures and arraysChapter 4 flow control structures and arrays
Chapter 4 flow control structures and arrays
 
Control All
Control AllControl All
Control All
 
C language UPTU Unit3 Slides
C language UPTU Unit3 SlidesC language UPTU Unit3 Slides
C language UPTU Unit3 Slides
 
PHP Tutorials
PHP TutorialsPHP Tutorials
PHP Tutorials
 
PHP Tutorials
PHP TutorialsPHP Tutorials
PHP Tutorials
 
Php Operators N Controllers
Php Operators N ControllersPhp Operators N Controllers
Php Operators N Controllers
 
Looping statement
Looping statementLooping statement
Looping statement
 
Php Loop
Php LoopPhp Loop
Php Loop
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
PHP MATERIAL
PHP MATERIALPHP MATERIAL
PHP MATERIAL
 
Php
PhpPhp
Php
 
Web development
Web developmentWeb development
Web development
 
Ap Power Point Chpt3
Ap Power Point Chpt3Ap Power Point Chpt3
Ap Power Point Chpt3
 
C Constructs (C Statements & Loop)
C Constructs (C Statements & Loop)C Constructs (C Statements & Loop)
C Constructs (C Statements & Loop)
 
Babitha5.php
Babitha5.phpBabitha5.php
Babitha5.php
 
Php
PhpPhp
Php
 
Babitha5.php
Babitha5.phpBabitha5.php
Babitha5.php
 
Babitha5.php
Babitha5.phpBabitha5.php
Babitha5.php
 
Final requirement
Final requirementFinal requirement
Final requirement
 

Más de lotlot

Pseudocode-Flowchart
Pseudocode-FlowchartPseudocode-Flowchart
Pseudocode-Flowchartlotlot
 
Form Script
Form ScriptForm Script
Form Scriptlotlot
 
Mysql Aggregate
Mysql AggregateMysql Aggregate
Mysql Aggregatelotlot
 
Mysql Script
Mysql ScriptMysql Script
Mysql Scriptlotlot
 
Php Form
Php FormPhp Form
Php Formlotlot
 
Php-Continuation
Php-ContinuationPhp-Continuation
Php-Continuationlotlot
 
Hariyali - India
Hariyali - IndiaHariyali - India
Hariyali - Indialotlot
 
The Province Of Davao Oriental
The Province Of Davao OrientalThe Province Of Davao Oriental
The Province Of Davao Orientallotlot
 
Annual Review
Annual ReviewAnnual Review
Annual Reviewlotlot
 

Más de lotlot (10)

Pseudocode-Flowchart
Pseudocode-FlowchartPseudocode-Flowchart
Pseudocode-Flowchart
 
Form Script
Form ScriptForm Script
Form Script
 
Mysql Aggregate
Mysql AggregateMysql Aggregate
Mysql Aggregate
 
Mysql Script
Mysql ScriptMysql Script
Mysql Script
 
Mysql
MysqlMysql
Mysql
 
Php Form
Php FormPhp Form
Php Form
 
Php-Continuation
Php-ContinuationPhp-Continuation
Php-Continuation
 
Hariyali - India
Hariyali - IndiaHariyali - India
Hariyali - India
 
The Province Of Davao Oriental
The Province Of Davao OrientalThe Province Of Davao Oriental
The Province Of Davao Oriental
 
Annual Review
Annual ReviewAnnual Review
Annual Review
 

Último

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
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 2024Rafal Los
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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 AutomationSafe Software
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
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.pdfsudhanshuwaghmare1
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 

Último (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

Php Condition Flow

  • 2. The if Statement An if statement is a way of controlling the execution of a statement that follows it (that is, a single statement or a block of code inside braces). The if statement evaluates an expression between parentheses. If this expression results in a true value, the statement is executed. Otherwise, the statement is skipped entirely. This enables scripts to make decisions based on any number of factors. if (expression) { // code to execute if the expression evaluates to true }
  • 3. Sample #1 <?php $satisfied = "very"; if ( $satisfied == "very" ) { echo"We are pleased that you are happy with our service"; // register customer satisfaction in some way } ?>
  • 4. Using the else Clause with the if Statement When working with the if statement, you will often want to define an alternative block of code that should be executed if the expression you are testing evaluates to false. You can do this by adding else to the if statement followed by a further block of code, like so: if (expression) { // code to execute if the expression evaluates to true } else { // code to execute in all other cases }
  • 5. Sample #2 <?php // $satisfied = "very"; if ( $satisfied == "very" ) { echo "We are pleased that you are happy with our service"; // register customer satisfaction in some way } else { echo "Please take a moment to rate our service"; // present pulldown } ?>
  • 6. Using the else if Clause with the if Statement You can use an if/else else/if construct to test multiple expressions before offering a default block of code: if ( expression ) { // code to execute if the expression evaluates to true } else if ( another expression ) { // code to execute if the previous expression failed // and this one evaluates to true } else { // code to execute in all other cases }
  • 7. Sample #3 <?php $satisfied = "no"; if ( $satisfied == "very" ) { echo "We are pleased that you are happy with our service"; // register customer satisfaction in some way } else if ( $satisfied == "no") { echo "We are sorry that we have not met your expectations"; // request further feedback } else { echo "Please take a moment to rate our service"; // present pulldown } ?>
  • 8. The switch Statement The switch statement is an alternative way of changing program flow according to the evaluation of an expression. . Using the if statement in conjunction with else if, you can evaluate multiple expressions. Switch evaluates only one expression, executing different code according to the result of that expression, as long as the expression evaluates to a simple type (a number, string, or Boolean). switch (expression) { case result1: // execute this if expression results in result1 break; case result2: // execute this if expression results in result2 break; default: // execute this if no break statement // has been encountered hitherto }
  • 9. Sample #4 <?php $satisfied = "no"; switch ( $satisfied ) { case "very": echo "We are pleased that you are happy with our service"; break; case "no“: echo "We are sorry that we have not met your expectations"; break; default: echo "Please take a moment to rate our service"; 21: } ?>