PHP<br />Conditional Logic<br />
The if Statement<br />An if statement is a way of controlling the execution of a statement that follows it (that is, a sin...
Sample #1<br />&lt;?php<br /> $satisfied = &quot;very&quot;; <br /> if ( $satisfied == &quot;very&quot; ) { <br />echo&quo...
Using the else Clause with the if Statement<br />When working with the if statement, you will often want to define an alte...
Sample #2<br />&lt;?php<br />// $satisfied = &quot;very&quot;;<br />if ( $satisfied == &quot;very&quot; ) {<br />echo &quo...
Using the else if Clause with the if Statement<br />You can use an if/else else/if construct to test multiple expressions ...
Sample #3<br />&lt;?php<br />$satisfied = &quot;no&quot;; <br />if ( $satisfied == &quot;very&quot; ) { <br />echo &quot;W...
The switch Statement<br />The switch statement is an alternative way of changing program flow according to the evaluation ...
Sample #4<br />&lt;?php<br />$satisfied = &quot;no&quot;; <br />switch ( $satisfied ) { <br />case &quot;very&quot;: <br /...
Thank You!<br />
Upcoming SlideShare
Loading in …5
×

Php Condition Flow

1,314
-1

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,314
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Php Condition Flow

  1. 1. PHP<br />Conditional Logic<br />
  2. 2. The if Statement<br />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.<br /> if (expression) { <br /> // code to execute if the expression evaluates to true <br /> } <br />
  3. 3. Sample #1<br />&lt;?php<br /> $satisfied = &quot;very&quot;; <br /> if ( $satisfied == &quot;very&quot; ) { <br />echo&quot;We are pleased that you are happy with our service&quot;; <br /> // register customer satisfaction in some way <br />} <br />?&gt; <br />
  4. 4. Using the else Clause with the if Statement<br />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:<br /> if (expression) { <br /> // code to execute if the expression evaluates to true <br /> } else { <br /> // code to execute in all other cases<br />} <br />
  5. 5. Sample #2<br />&lt;?php<br />// $satisfied = &quot;very&quot;;<br />if ( $satisfied == &quot;very&quot; ) {<br />echo &quot;We are pleased that you are happy with our service&quot;; <br />// register customer satisfaction in some way<br />} else { <br />echo &quot;Please take a moment to rate our service&quot;;<br />// present pulldown<br />} <br />?&gt; <br />
  6. 6. Using the else if Clause with the if Statement<br />You can use an if/else else/if construct to test multiple expressions before offering a default block of code:<br />if ( expression ) { <br />// code to execute if the expression evaluates to true <br />} else if ( another expression ) { <br />// code to execute if the previous expression failed <br />// and this one evaluates to true <br /> } else { <br /> // code to execute in all other cases <br /> } <br />
  7. 7. Sample #3<br />&lt;?php<br />$satisfied = &quot;no&quot;; <br />if ( $satisfied == &quot;very&quot; ) { <br />echo &quot;We are pleased that you are happy with our service&quot;; <br />// register customer satisfaction in some way <br />} else if ( $satisfied == &quot;no&quot;) { <br />echo &quot;We are sorry that we have not met your expectations&quot;; <br />// request further feedback <br />} else {<br />echo &quot;Please take a moment to rate our service&quot;; <br />// present pulldown<br />}<br />?&gt; <br />
  8. 8. The switch Statement<br />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). <br /> switch (expression) { <br /> case result1: <br /> // execute this if expression results in result1 <br /> break; <br /> case result2: <br /> // execute this if expression results in result2 <br /> break; <br /> default: <br /> // execute this if no break statement <br /> // has been encountered hitherto <br /> } <br />
  9. 9. Sample #4<br />&lt;?php<br />$satisfied = &quot;no&quot;; <br />switch ( $satisfied ) { <br />case &quot;very&quot;: <br />echo &quot;We are pleased that you are happy with our service&quot;; <br />break; <br />case &quot;no“:<br />echo &quot;We are sorry that we have not met your expectations&quot;; <br />break; <br />default: <br />echo &quot;Please take a moment to rate our service&quot;; 21: <br />} <br />?&gt; <br />
  10. 10. Thank You!<br />
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×