Results 1 to 6 of 6

Thread: How to use Else and Else If Statement in PHP?

  1. #1
    Join Date
    Apr 2009
    Posts
    745

    How to use Else and Else If Statement in PHP?

    Hi friends,
    I have studied the different statements that are used in programming language, but I have never use the statements in PHP. So thought to take some tips from you guys so that I can use that statements in PHP also. Please tell me how to use Else and Else If Statement in PHP? Also provide me some sample of coding, so that I can understand it more clearly.

  2. #2
    Join Date
    Aug 2006
    Posts
    235

    Re: How to use Else and Else If Statement in PHP?

    In many cases, you want to execute a statement if a condition is met, and another statement if the condition is not met. This is what else is. Else runs an if and executes instructions corresponding to the case where the if expression is FALSE. Conditional statements are used to perform different actions based on different conditions.
    3.2 (northwood)
    2gig ram
    ATI AIW X800xt 256mb
    Gigabyte GA-8knxp 875p Chipset
    Optiwrite 8X DVD Burner
    Win XP PRO Sp2 (Works Perfectly)
    2 SATA Raptor 74gig Raid 0
    2 7200 IDE 320gig HD

  3. #3
    Join Date
    Nov 2008
    Posts
    1,192

    Re: How to use Else and Else If Statement in PHP?

    I am providing you with an example so that you can understand the concept of else statement :
    PHP Code:
    <?php
    if ($a $b) {
      echo 
    "a is greater than b";
    } else {
      echo 
    "a is NOT greater than b";
    }
    ?>
    Hope that you can also use this statement.

  4. #4
    Join Date
    Jul 2006
    Posts
    442

    Re: How to use Else and Else If Statement in PHP?

    Instructions after the else are executed if the if expression is FALSE, and if not followed by the expression elseif - only if they evaluated to FALSE. elseif, as its name suggests, is a combination of if and else. Like else, it allows to execute a statement after an if in case the original if expression evaluates to FALSE. But, unlike else, it will execute the instruction that if the elseif conditional expression evaluates to TRUE.
    "When they give you ruled paper, write the other way..." J.R.J.

  5. #5
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How to use Else and Else If Statement in PHP?

    You can have multiple elseif which follow one after the other after an if statement. Elseif The first to be evaluated to TRUE would be executed. In PHP, you can also write 'else if' in both words and behavior will be identical to the version in one word. The syntactic meaning is slightly different, but ultimately, the result will be exactly the same. Elseif expression is only executed if the preceding if and any preceding elseif expressions evaluated to FALSE, and elseif expression evaluated to TRUE.

  6. #6
    Join Date
    Nov 2008
    Posts
    996

    Re: How to use Else and Else If Statement in PHP?

    The following is an example of Else If statement, :
    PHP Code:
    <?php
    if ($a $b) {
        echo 
    "a is bigger than b";
    } elseif (
    $a == $b) {
        echo 
    "a is equal to b";
    } else {
        echo 
    "a is smaller than b";
    }
    ?>
    Hope that this sample of coding helps you.!!

Similar Threads

  1. SQL statement problem in C#
    By AMISH in forum Software Development
    Replies: 4
    Last Post: 01-06-2010, 01:17 PM
  2. How to use If statement in PHP?
    By Deabelos in forum Software Development
    Replies: 4
    Last Post: 09-02-2010, 06:14 AM
  3. HTML if else statement
    By Darthmouth in forum Software Development
    Replies: 3
    Last Post: 02-09-2009, 06:02 PM
  4. If Statement in HTML
    By Beatrisa in forum Software Development
    Replies: 3
    Last Post: 07-08-2009, 02:33 PM
  5. Replies: 4
    Last Post: 25-02-2009, 08:52 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,500,929.99545 seconds with 17 queries