Detri Amelia Chandra
  • HOME
  • GIS
  • HTML
  • Bootstrap
  • CSS
  • Javascript
  • Ubuntu
  • Useful Tools
    • URL Redirect Tool
    • URL Download Encryptor
No Result
View All Result
Detriamelia.com
  • HOME
  • GIS
  • HTML
  • Bootstrap
  • CSS
  • Javascript
  • Ubuntu
  • Useful Tools
    • URL Redirect Tool
    • URL Download Encryptor
No Result
View All Result
Detriamelia.com
No Result
View All Result

7. Understanding PHP Condition If Else, Elseif Statements

15/01/2020
in PHP, Programming
Understanding PHP Condition If Else, Elseif Statements

Understanding PHP Condition If Else, Elseif Statements

The opportunity this time, let’s discuss about the conditions in PHP. Contingent explanations are utilized to perform various activities dependent on various conditions.

PHP Conditional Statements

All the time when you compose code, you need to perform various activities for various conditions. You can utilize restrictive articulations in your code to do this.
In PHP we have the accompanying contingent articulations:

  • if statement – executes some code if one condition is true
  • if…else statement – executes some code if a condition is true and another code if that condition is false
  • if…elseif…else statement – executes different codes for more than two conditions
  • switch statement – selects one of many blocks of code to be executed

The if statement executes some code if one condition is true.
See the example below. Output “Have a good day!” if the current time (HOUR) is less than 20:

1
2
3
4
5
6
<?php
$t = date("H");
if ($t < "20") {
    echo "Have a good day!";
}
?>

The If Else Statements

The if…else statement executes some code if a condition is true and another code if that condition is false.
See the example below. Output “Have a good day!” if the current time is less than 20, and “Have a good night!” otherwise:

1
2
3
4
5
6
7
8
<?php
$t = date("H");
if ($t < "20") {
    echo "Have a good day!";
} else {
    echo "Have a good night!";
}
?>

The If… Else If… Else Statements

The if…elseif…else statement executes different codes for more than two conditions.
See the example below. Output “Have a good morning!” if the current time is less than 10, and “Have a good day!” if the current time is less than 20. Otherwise it will output “Have a good night!”:

1
2
3
4
5
6
7
8
9
10
<?php
$t = date("H");
if ($t < "10") {
    echo "Have a good morning!";
} elseif ($t < "20") {
    echo "Have a good day!";
} else {
    echo "Have a good night!";
}
?>

 

Tags: PHP
ShareTweetShare

Related Posts

Learn Python Basics for Beginners: Easy Ways to Understand the Python Programming Language
Python

Learn Python Basics for Beginners: Easy Ways to Understand the Python Programming Language

Python is a high-level programming language that can be used to create a wide range of applications. Python was created...

09/08/2023
Database Table Relations Using Join Operations and the Classical Model
Belajar PHP

Database Table Relations Using Join Operations and the Classical Model

MySQL is a highly popular relational database in today's programming world. With features that allow for table-to-table relationships, MySQL databases...

09/08/2023
PHP Forms - Validation With Required Fields
PHP

14. PHP Forms – Validation With Required Fields

Hi everyone, this time we will discuss about PHP Validation using the Required Field. Not many people know, it turns...

15/02/2020
PHP Form Handling
PHP

13. New Performing PHP Form Handling

Detriamelia.Com - Running form functions in PHP is not difficult. By using the $ _POST and $ _GET methods it...

13/02/2020
Next Post
PHP Switch Statement

8. PHP Switch Statement

PHP Loop (While, For, Foreach) Definition and Example

9. PHP Loop (While, For, Foreach) Definition and Example

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recommended

Understanding PHP Condition If Else, Elseif Statements

7. Understanding PHP Condition If Else, Elseif Statements

15/01/2020
Database Table Relations Using Join Operations and the Classical Model

Database Table Relations Using Join Operations and the Classical Model

09/08/2023
PHP Function Definition and Example

10. PHP Function Definition and Example

15/01/2020
install-apache-mysql-and-php-in-ubuntu-18-04-lts-part-2

2. How to Install Apache, MySQL and PHP in Ubuntu 18.04 LTS Part 1

11/11/2019

Instagram Feed

    The Instagram Access Token is expired, Go to the Customizer > JNews : Social, Like & View > Instagram Feed Setting, to refresh it.
  • HOME
  • GIS
  • HTML
  • Bootstrap
  • CSS
  • Javascript
  • Ubuntu
  • Useful Tools
Detriamelia.Com

© 2022 Detri Amelia Chandra - IT Tips and Programming Tutorials.

No Result
View All Result
  • HOME
  • GIS
  • HTML
  • Bootstrap
  • CSS
  • Javascript
  • Ubuntu
  • Useful Tools
    • URL Redirect Tool
    • URL Download Encryptor