Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



How to use Else and Else If Statement in PHP?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 05-03-2010
Member
 
Join Date: Apr 2009
Posts: 732
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.

Reply With Quote
  #2  
Old 05-03-2010
Member
 
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
Reply With Quote
  #3  
Old 05-03-2010
Member
 
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.
Reply With Quote
  #4  
Old 05-03-2010
Member
 
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.
Reply With Quote
  #5  
Old 05-03-2010
Member
 
Join Date: Apr 2008
Posts: 2,001
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.
Reply With Quote
  #6  
Old 05-03-2010
Member
 
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.!!
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to use Else and Else If Statement in PHP?"
Thread Thread Starter Forum Replies Last Post
SQL statement problem in C# AMISH Software Development 4 01-06-2010 01:17 PM
How to use If statement in PHP? Deabelos Software Development 4 09-02-2010 06:14 AM
HTML if else statement Darthmouth Software Development 3 02-09-2009 06:02 PM
If Statement in HTML Beatrisa Software Development 3 07-08-2009 02:33 PM
What is the difference between while statement & do statement? Athos Software Development 4 25-02-2009 08:52 PM


All times are GMT +5.5. The time now is 09:58 AM.