Php Condition Flow
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Php Condition Flow

on

  • 1,471 views

 

Statistics

Views

Total Views
1,471
Views on SlideShare
1,471
Embed Views
0

Actions

Likes
0
Downloads
3
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Php Condition Flow Presentation Transcript

  • 1. PHP
    Conditional Logic
  • 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:
    }
    ?>
  • 10. Thank You!