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

7. Understanding PHP Condition If Else, Elseif Statements

Detri Amelia Chandra by Detri Amelia Chandra
15/01/2020
in PHP, Programming
0
Understanding PHP Condition If Else, Elseif Statements

Understanding PHP Condition If Else, Elseif Statements

0
SHARES
98
VIEWS
Share on FacebookShare on Twitter

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

Recommended Post

Relasi Tabel Database Menggunakan Operasi Join dan Model Klasik

14. PHP Forms – Validation With Required Fields

14. PHP Forms – Validation With Required Fields

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
Previous Post

6. Detailed Explanation of PHP Data Types

Next Post

8. PHP Switch Statement

Related Posts

Relasi Tabel Database Menggunakan Operasi Join dan Model Klasik

Relasi Tabel Database Menggunakan Operasi Join dan Model Klasik

30/04/2020
PHP Forms - Validation With Required Fields

14. PHP Forms – Validation With Required Fields

15/02/2020
PHP Forms - Validation With Required Fields

14. PHP Forms – Validation With Required Fields

15/02/2020
PHP Form Handling

13. New Performing PHP Form Handling

13/02/2020
Learn PHP Global Variables - Superglobals With Example

12. Learn PHP Global Variables – Superglobals With Example

20/01/2020
PHP Array Example, Complete Editions

11. PHP Array Example, Complete Editions

17/01/2020
Next Post
PHP Switch Statement

8. PHP Switch Statement

Tinggalkan Balasan Batalkan balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *

Top Stories

Relasi Tabel Database Menggunakan Operasi Join dan Model Klasik

Relasi Tabel Database Menggunakan Operasi Join dan Model Klasik

30/04/2020
PEMROGRAMAN WEB DAN PERANGKAT BERGERAK – PERPUSTAKAAN PART-1

Pemrograman Web dan Perangkat Bergerak – Perpustakaan Part-1

16/04/2020
PEMROGRAMAN WEB DAN PERANGKAT BERGERAK – PERPUSTAKAAN PART-1

Pemrograman Web dan Perangkat Bergerak – Perpustakaan Part-1

16/04/2020

News & More

Categories

  • Counseling
  • Consultations
  • Relationship
  • Friendship
  • Singlehood

About Us

We bring you the best Premium WordPress Themes that perfect for news, magazine, personal blog, etc. Check our landing page for details.

Connect on Social

© 2019 JNews - Premium WordPress news & magazine theme by Jegtheme.

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

© 2021 Detri Amelia Chandra - IT Tips and Programming Tutorial.