SlideShare uma empresa 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!

Mais conteúdo relacionado

Mais procurados

Mais procurados (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
 

Semelhante a Php Condition Flow

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
sshhzap
 
Php Operators N Controllers
Php Operators N ControllersPhp Operators N Controllers
Php Operators N Controllers
mussawir20
 
Looping statement
Looping statementLooping statement
Looping statement
ilakkiya
 
Php Loop
Php LoopPhp Loop
Php Loop
lotlot
 
Ap Power Point Chpt3
Ap Power Point Chpt3Ap Power Point Chpt3
Ap Power Point Chpt3
dplunkett
 

Semelhante 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
 

Mais de lotlot

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

Mais 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

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

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
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 

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: } ?>