Php – If..Elseif..Else Conditional Statements

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/php-if-elseif-else-conditional-statements/
PINTEREST
PINTEREST
INSTAGRAM

PHP Tutorial Topics

  1. Introduction To PHP
  2. Installing PHP To Linux
  3. Installing PHP To Windows
  4. PHP Hello World Project with Eclipse
  5. PHP Syntax
  6. PHP Variables and Types
  7. PHP String Types
  8. PHP Numeric Type (Integer, Float, Double)
  9. PHP Boolean Type
  10. PHP Arrays
  11. PHP Operators
  12. PHP Ternary Operators
  13. PHP Constants
  14. PHP If..Elseif..Else Conditional Statements
  15. PHP Switch..Case Conditional Statements
  16. PHP For and Foreach Loop Statements
  17. PHP While and Do While Statements
  18. PHP Functions
  19. PHP Class and Objects
  20. PHP Date and Time Operations

Php provides ability to write applications according to decision making with given statements or comparative tests. We can test given situations and conditions and dictate application execution. For example we want to check given integer value and print the positiveness and negativeness. Here we need to check this situation with if-elseif-else conditional statements.

If Statement

If statement will check given condition and if the condition is true if statement code block will be executed, if not it will be simply skipped. Here the if statement syntax.

I think the best way to understand the if statement is doing simple and clear example. We have a integer variables named $temp which holds temperature and we want to check whether the temperature if higher then 0 . If so we will print Temperature is above 0 .

Here most important part is $temp>0 where $temp value will be compared with comparison operator > and an boolean result like true will be returned.

If..Elseif Statement

In previous example we have check only one condition but real world is different and more complex than that. We generally check multiple conditions in a single if..elseif statement. This statement will start with if and then for each condition we will add an elseif statement like below.

In this example we will check student name which is hold variable named $student . If the condition met we will print the name.

As we expect last elseif statement condition will match and print Ali . Thre is no restriction about the count of additional elseif statements.

If..Elseif..Else Statement

We can precisely specify the conditions and mathes. But what if we want to specify completely unmatched situation and run execute some code. We can use else statement at the end of the if..elseif statement block and this means run if none of above conditions matched.

In this example we will check $count and if none of the statements mathed we will print empty .

PHP Tutorial Topics

  1. Introduction To PHP
  2. Installing PHP To Linux
  3. Installing PHP To Windows
  4. PHP Hello World Project with Eclipse
  5. PHP Syntax
  6. PHP Variables and Types
  7. PHP String Types
  8. PHP Numeric Type (Integer, Float, Double)
  9. PHP Boolean Type
  10. PHP Arrays
  11. PHP Operators
  12. PHP Ternary Operators
  13. PHP Constants
  14. PHP If..Elseif..Else Conditional Statements
  15. PHP Switch..Case Conditional Statements
  16. PHP For and Foreach Loop Statements
  17. PHP While and Do While Statements
  18. PHP Functions
  19. PHP Class and Objects
  20. PHP Date and Time Operations
RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/php-if-elseif-else-conditional-statements/
PINTEREST
PINTEREST
INSTAGRAM

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)