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

Cara Mudah Memahami Bahasa Pemrograman Python
Python

Belajar Dasar-dasar Python untuk Pemula: Cara Mudah Memahami Bahasa Pemrograman Python

Python adalah bahasa pemrograman tingkat tinggi yang dapat digunakan untuk membuat berbagai macam aplikasi. Python diciptakan oleh Guido van Rossum...

06/03/2023
Relasi Tabel Database Menggunakan Operasi Join dan Model Klasik
Belajar PHP

Relasi Tabel Database Menggunakan Operasi Join dan Model Klasik

MySQL adalah database relational yang sangat populer di dunia programming hari ini. Dengan memiliki fitur yang bisa dikaitkan antar tabel,...

30/04/2020
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

Easy to Identify Identity Card Number (NIK) Using PHP

Easy to Identify Identity Card Number (NIK) Using PHP

27/03/2019
PHP Syntax, Variables and PHP Echo/Print

4. PHP Syntax and PHP Variables

29/11/2019
PHP Loop (While, For, Foreach) Definition and Example

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

15/01/2020
PHP Syntax, Variables and PHP Echo/Print

5. PHP Echo and Print Statements

29/11/2019

Instagram Feed

  • Sekolah sambil bermain...
  • Produk mahasiswa semester 5 Pendidikan Teknologi Informasi STKIP Rokania..
Kran dispenser otomatis (sensor)
#arduino
#PTI Ok
#STKIPRokania
#AyoKuliahDiRokania
  • Salah satu produk mahasiswa Pendidikan Teknologi Informasi STKIP Rokania...Pemanfaatan Internet Of Thing pada Lampu dan CCTV otomatis dengan Telegram Bot..

#StkipRokania
#PendidikanTeknologiInformasi
  • "Golden Time" yang tidak bisa diputar dan diulang tetapi tersimpan di inner child nya dan diingat selamanya..
  • Selamat atas M.Kom nya yah...semoga ada Reski untuk studi selanjutnya ya...
  • 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