SlideShare ist ein Scribd-Unternehmen logo
1 von 8
Downloaden Sie, um offline zu lesen
Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood
1
Chapter 5
Part II
PHP
PHP if...else...elseif Statements:
Conditional statements are used to perform different actions based on
different conditions.
In PHP we have the following conditional statements:
 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
1. PHP - The if Statement
The if statement executes some code if one condition is true.
Syntax
if (condition) {
code to be executed if condition is true;
}
Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood
2
The example below will output "Have a good day!" if the current time
(HOUR) is less than 20:
Example
<?php
$t = date("H");
if ($t < "20") {
echo "Have a good day!";
}
?>
2. PHP - The if...else Statement
The if....else statement executes some code if a condition is true and
another code if that condition is false.
Syntax
if (condition) {
code to be executed if condition is true;
} else {
code to be executed if condition is false;
}
The example below will output "Have a good day!" if the current time is
less than 20, and "Have a good night!" otherwise:
Example
<?php
$t = date("H");
if ($t < "20") {
echo "Have a good day!";
Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood
3
} else {
echo "Have a good night!";
}
?>
3. PHP - The if...elseif....else Statement
The if....elseif...else statement executes different codes for more than
two conditions.
Syntax
if (condition) {
code to be executed if this condition is true;
} elseif (condition) {
code to be executed if this condition is true;
} else {
code to be executed if all conditions are false;
}
The example below will 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!":
Example
<?php
$t = date("H");
if ($t < "10") {
echo "Have a good morning!";
} elseif ($t < "20") {
echo "Have a good day!";
} else {
Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood
4
echo "Have a good night!";
}
?>
4. The PHP switch Statement
Use the switch statement to select one of many blocks of code to be
executed.
Syntax
switch (n) {
case label1:
code to be executed if n=label1;
break;
case label2:
code to be executed if n=label2;
break;
case label3:
code to be executed if n=label3;
break;
...
default:
code to be executed if n is different from all
labels;
}
This is how it works: First we have a single expression n (most often a variable),
that is evaluated once. The value of the expression is then compared with the
values for each case in the structure. If there is a match, the block of code
associated with that case is executed. Use break to prevent the code from running
into the next case automatically. The default statement is used if no match is
found.
Example
<?php
$favcolor = "red";
Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood
5
switch ($favcolor) {
case "red":
echo "Your favorite color is red!";
break;
case "blue":
echo "Your favorite color is blue!";
break;
case "green":
echo "Your favorite color is green!";
break;
default:
echo "Your favorite color is neither red, blue, nor
green!";
}
?>
5.PHP while Loops
The while loop executes a block of code as long as the specified
condition is true.
Syntax
while (condition is true) {
code to be executed;
}
The example below first sets a variable $x to 1 ($x = 1). Then, the while
loop will continue to run as long as $x is less than, or equal to 5 ($x <=
5). $x will increase by 1 each time the loop runs ($x++):
Example
<?php
$x = 1;
Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood
6
while($x <= 5) {
echo "The number is: $x <br>";
$x++;
}
?>
6. The PHP do...while Loop
The do...while loop will always execute the block of code once, it will
then check the condition, and repeat the loop while the specified
condition is true.
Syntax
do {
code to be executed;
} while (condition is true);
The example below first sets a variable $x to 1 ($x = 1). Then, the do
while loop will write some output, and then increment the variable $x
with 1. Then the condition is checked (is $x less than, or equal to 5?),
and the loop will continue to run as long as $x is less than, or equal to 5:
Example
<?php
$x = 1;
do {
Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood
7
echo "The number is: $x <br>";
$x++;
} while ($x <= 5);
?>
7. The PHP for Loop
The for loop is used when you know in advance how many times the
script should run.
Syntax
for (init counter; test counter; increment counter) {
code to be executed;
}
Parameters:
•init counter: Initialize the loop counter value
•test counter: Evaluated for each loop iteration. If it evaluates to TRUE,
the loop continues. If it evaluates to FALSE, the loop ends.
•increment counter: Increases the loop counter value
The example below displays the numbers from 0 to 10:
Example
<?php
for ($x = 0; $x <= 10; $x++) {
echo "The number is: $x <br>";
Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood
8
}
?>
8. The PHP foreach Loop
The foreach loop works only on arrays, and is used to loop through each
key/value pair in an array.
Syntax
foreach ($array as $value) {
code to be executed;
}
For every loop iteration, the value of the current array element is
assigned to $value and the array pointer is moved by one, until it reaches
the last array element.
The following example demonstrates a loop that will output the values
of the given array ($colors):
Example
<?php
$colors = array("red", "green", "blue", "yellow");
foreach ($colors as $value) {
echo "$value <br>";
}
?>

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Basics PHP
Basics PHPBasics PHP
Basics PHP
 
Php, mysq lpart4(processing html form)
Php, mysq lpart4(processing html form)Php, mysq lpart4(processing html form)
Php, mysq lpart4(processing html form)
 
What Is Php
What Is PhpWhat Is Php
What Is Php
 
Php, mysq lpart1
Php, mysq lpart1Php, mysq lpart1
Php, mysq lpart1
 
Control Structures In Php 2
Control Structures In Php 2Control Structures In Php 2
Control Structures In Php 2
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
 
PHP Basic
PHP BasicPHP Basic
PHP Basic
 
PHP Basic & Variables
PHP Basic & VariablesPHP Basic & Variables
PHP Basic & Variables
 
Operators in PHP
Operators in PHPOperators in PHP
Operators in PHP
 
Php string function
Php string function Php string function
Php string function
 
php basics
php basicsphp basics
php basics
 
Php basics
Php basicsPhp basics
Php basics
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
PHP-Part1
PHP-Part1PHP-Part1
PHP-Part1
 
Php Lecture Notes
Php Lecture NotesPhp Lecture Notes
Php Lecture Notes
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Php a dynamic web scripting language
Php   a dynamic web scripting languagePhp   a dynamic web scripting language
Php a dynamic web scripting language
 
PHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet SolutionPHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet Solution
 
Chapter 02 php basic syntax
Chapter 02   php basic syntaxChapter 02   php basic syntax
Chapter 02 php basic syntax
 

Andere mochten auch

Performance d'un site Internet
Performance d'un site InternetPerformance d'un site Internet
Performance d'un site InternetVaisonet
 
Case Study - Performance Assessment and Testing Helps Government Department I...
Case Study - Performance Assessment and Testing Helps Government Department I...Case Study - Performance Assessment and Testing Helps Government Department I...
Case Study - Performance Assessment and Testing Helps Government Department I...Cigniti Technologies Ltd
 
CV Bernard Maselis - 2015 (EN)
CV Bernard Maselis - 2015 (EN)CV Bernard Maselis - 2015 (EN)
CV Bernard Maselis - 2015 (EN)Bernard Maselis
 
Personality Profile Training
Personality Profile TrainingPersonality Profile Training
Personality Profile TrainingMichaelSHickman
 
Case Study - Functional Testing Helps Leading Movie Service Company Minimize ...
Case Study - Functional Testing Helps Leading Movie Service Company Minimize ...Case Study - Functional Testing Helps Leading Movie Service Company Minimize ...
Case Study - Functional Testing Helps Leading Movie Service Company Minimize ...Cigniti Technologies Ltd
 
21 avril 2015 : la compatibilité mobile, critère SEO officiel chez Google
21 avril 2015 : la compatibilité mobile, critère SEO officiel chez Google21 avril 2015 : la compatibilité mobile, critère SEO officiel chez Google
21 avril 2015 : la compatibilité mobile, critère SEO officiel chez GoogleAurélien Delefosse
 
المادة العلمية محاضرة 3 تبويب المراجع العلمية باستخدام برنامج endnote
المادة العلمية محاضرة 3 تبويب المراجع العلمية باستخدام برنامج endnoteالمادة العلمية محاضرة 3 تبويب المراجع العلمية باستخدام برنامج endnote
المادة العلمية محاضرة 3 تبويب المراجع العلمية باستخدام برنامج endnoteمركز البحوث الأقسام العلمية
 
توظيف وسائل الإعلام الاجتماعي في العمل الخيري - تجربة عالمية
توظيف وسائل الإعلام الاجتماعي في العمل الخيري - تجربة عالميةتوظيف وسائل الإعلام الاجتماعي في العمل الخيري - تجربة عالمية
توظيف وسائل الإعلام الاجتماعي في العمل الخيري - تجربة عالميةAyman Hamdan
 
Le Content Marketing stratégique, la méthodologie SCOM (& scompler / Scribble...
Le Content Marketing stratégique, la méthodologie SCOM (& scompler / Scribble...Le Content Marketing stratégique, la méthodologie SCOM (& scompler / Scribble...
Le Content Marketing stratégique, la méthodologie SCOM (& scompler / Scribble...Mael Roth
 
Symantec Data Insight 3.0
Symantec Data Insight 3.0Symantec Data Insight 3.0
Symantec Data Insight 3.0Symantec
 
Interview Métier : Web Designer / Intégrateur
Interview Métier : Web Designer / Intégrateur Interview Métier : Web Designer / Intégrateur
Interview Métier : Web Designer / Intégrateur #SUPDEWEB
 
Facebook Insights Reports
Facebook Insights ReportsFacebook Insights Reports
Facebook Insights ReportsReportGarden
 
MÉMOIRE DE FIN D'ÉTUDE - LA COMMUNICATION DES CONCEPT-STORES
MÉMOIRE DE FIN D'ÉTUDE - LA COMMUNICATION DES CONCEPT-STORES MÉMOIRE DE FIN D'ÉTUDE - LA COMMUNICATION DES CONCEPT-STORES
MÉMOIRE DE FIN D'ÉTUDE - LA COMMUNICATION DES CONCEPT-STORES Gypsy Ferrari
 
KPI & acquisition de trafic - 2016
KPI & acquisition de trafic - 2016KPI & acquisition de trafic - 2016
KPI & acquisition de trafic - 2016Rollingbox
 
Etes vous prêts pour la révolution omnicanale imposée par le consommateur ?
Etes vous prêts pour la révolution omnicanale imposée par le consommateur ?Etes vous prêts pour la révolution omnicanale imposée par le consommateur ?
Etes vous prêts pour la révolution omnicanale imposée par le consommateur ?Marie Claude Delannoy
 

Andere mochten auch (20)

Psa Business Model
Psa Business ModelPsa Business Model
Psa Business Model
 
Performance d'un site Internet
Performance d'un site InternetPerformance d'un site Internet
Performance d'un site Internet
 
Case Study - Performance Assessment and Testing Helps Government Department I...
Case Study - Performance Assessment and Testing Helps Government Department I...Case Study - Performance Assessment and Testing Helps Government Department I...
Case Study - Performance Assessment and Testing Helps Government Department I...
 
CV Bernard Maselis - 2015 (EN)
CV Bernard Maselis - 2015 (EN)CV Bernard Maselis - 2015 (EN)
CV Bernard Maselis - 2015 (EN)
 
Personality Profile Training
Personality Profile TrainingPersonality Profile Training
Personality Profile Training
 
Case Study - Functional Testing Helps Leading Movie Service Company Minimize ...
Case Study - Functional Testing Helps Leading Movie Service Company Minimize ...Case Study - Functional Testing Helps Leading Movie Service Company Minimize ...
Case Study - Functional Testing Helps Leading Movie Service Company Minimize ...
 
21 avril 2015 : la compatibilité mobile, critère SEO officiel chez Google
21 avril 2015 : la compatibilité mobile, critère SEO officiel chez Google21 avril 2015 : la compatibilité mobile, critère SEO officiel chez Google
21 avril 2015 : la compatibilité mobile, critère SEO officiel chez Google
 
المادة العلمية محاضرة 3 تبويب المراجع العلمية باستخدام برنامج endnote
المادة العلمية محاضرة 3 تبويب المراجع العلمية باستخدام برنامج endnoteالمادة العلمية محاضرة 3 تبويب المراجع العلمية باستخدام برنامج endnote
المادة العلمية محاضرة 3 تبويب المراجع العلمية باستخدام برنامج endnote
 
20160907 myposeo weloveseo
20160907 myposeo weloveseo20160907 myposeo weloveseo
20160907 myposeo weloveseo
 
توظيف وسائل الإعلام الاجتماعي في العمل الخيري - تجربة عالمية
توظيف وسائل الإعلام الاجتماعي في العمل الخيري - تجربة عالميةتوظيف وسائل الإعلام الاجتماعي في العمل الخيري - تجربة عالمية
توظيف وسائل الإعلام الاجتماعي في العمل الخيري - تجربة عالمية
 
Le Content Marketing stratégique, la méthodologie SCOM (& scompler / Scribble...
Le Content Marketing stratégique, la méthodologie SCOM (& scompler / Scribble...Le Content Marketing stratégique, la méthodologie SCOM (& scompler / Scribble...
Le Content Marketing stratégique, la méthodologie SCOM (& scompler / Scribble...
 
Symantec Data Insight 3.0
Symantec Data Insight 3.0Symantec Data Insight 3.0
Symantec Data Insight 3.0
 
Interview Métier : Web Designer / Intégrateur
Interview Métier : Web Designer / Intégrateur Interview Métier : Web Designer / Intégrateur
Interview Métier : Web Designer / Intégrateur
 
Renault nissan
Renault nissanRenault nissan
Renault nissan
 
Facebook Insights Reports
Facebook Insights ReportsFacebook Insights Reports
Facebook Insights Reports
 
MÉMOIRE DE FIN D'ÉTUDE - LA COMMUNICATION DES CONCEPT-STORES
MÉMOIRE DE FIN D'ÉTUDE - LA COMMUNICATION DES CONCEPT-STORES MÉMOIRE DE FIN D'ÉTUDE - LA COMMUNICATION DES CONCEPT-STORES
MÉMOIRE DE FIN D'ÉTUDE - LA COMMUNICATION DES CONCEPT-STORES
 
KPI & acquisition de trafic - 2016
KPI & acquisition de trafic - 2016KPI & acquisition de trafic - 2016
KPI & acquisition de trafic - 2016
 
Etes vous prêts pour la révolution omnicanale imposée par le consommateur ?
Etes vous prêts pour la révolution omnicanale imposée par le consommateur ?Etes vous prêts pour la révolution omnicanale imposée par le consommateur ?
Etes vous prêts pour la révolution omnicanale imposée par le consommateur ?
 
Les origines du brand content
Les origines du brand contentLes origines du brand content
Les origines du brand content
 
Carte de voeux QualiQuanti 2016
Carte de voeux QualiQuanti 2016 Carte de voeux QualiQuanti 2016
Carte de voeux QualiQuanti 2016
 

Ähnlich wie PHP-Part2

Ähnlich wie PHP-Part2 (20)

Php.ppt
Php.pptPhp.ppt
Php.ppt
 
Intro to php
Intro to phpIntro to php
Intro to php
 
PHP - Web Development
PHP - Web DevelopmentPHP - Web Development
PHP - Web Development
 
FYBSC IT Web Programming Unit IV PHP and MySQL
FYBSC IT Web Programming Unit IV  PHP and MySQLFYBSC IT Web Programming Unit IV  PHP and MySQL
FYBSC IT Web Programming Unit IV PHP and MySQL
 
PHP
PHPPHP
PHP
 
Lesson 6 php if...else...elseif statements
Lesson 6   php if...else...elseif statementsLesson 6   php if...else...elseif statements
Lesson 6 php if...else...elseif statements
 
Free PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in IndiaFree PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in India
 
PHP MATERIAL
PHP MATERIALPHP MATERIAL
PHP MATERIAL
 
php
phpphp
php
 
Web Application Development using PHP Chapter 2
Web Application Development using PHP Chapter 2Web Application Development using PHP Chapter 2
Web Application Development using PHP Chapter 2
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 
Php i-slides
Php i-slidesPhp i-slides
Php i-slides
 
Php i-slides
Php i-slidesPhp i-slides
Php i-slides
 
Php i-slides
Php i-slidesPhp i-slides
Php i-slides
 
Php i-slides (2) (1)
Php i-slides (2) (1)Php i-slides (2) (1)
Php i-slides (2) (1)
 
Php basic for vit university
Php basic for vit universityPhp basic for vit university
Php basic for vit university
 
php41.ppt
php41.pptphp41.ppt
php41.ppt
 
PHP InterLevel.ppt
PHP InterLevel.pptPHP InterLevel.ppt
PHP InterLevel.ppt
 
php-I-slides.ppt
php-I-slides.pptphp-I-slides.ppt
php-I-slides.ppt
 
Basic of PHP
Basic of PHPBasic of PHP
Basic of PHP
 

Mehr von Ahmed Saihood (8)

Sessions &Cookies
Sessions &CookiesSessions &Cookies
Sessions &Cookies
 
HTTP & HTTPs
HTTP & HTTPsHTTP & HTTPs
HTTP & HTTPs
 
CSS
CSSCSS
CSS
 
XHTML
XHTMLXHTML
XHTML
 
HTML-Forms
HTML-FormsHTML-Forms
HTML-Forms
 
HTML-Part2
HTML-Part2HTML-Part2
HTML-Part2
 
HTML-Part1
HTML-Part1HTML-Part1
HTML-Part1
 
internet basics
internet basics internet basics
internet basics
 

Kürzlich hochgeladen

WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)Delhi Call girls
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024APNIC
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLimonikaupta
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Servicegwenoracqe6
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...Neha Pandey
 
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Standkumarajju5765
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebJames Anderson
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Delhi Call girls
 
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.soniya singh
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxellan12
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...Escorts Call Girls
 
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445ruhi
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.CarlotaBedoya1
 
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girladitipandeya
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...APNIC
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGAPNIC
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Sheetaleventcompany
 

Kürzlich hochgeladen (20)

WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
 
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
 
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
 
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
 
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOG
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
 

PHP-Part2

  • 1. Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood 1 Chapter 5 Part II PHP PHP if...else...elseif Statements: Conditional statements are used to perform different actions based on different conditions. In PHP we have the following conditional statements:  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 1. PHP - The if Statement The if statement executes some code if one condition is true. Syntax if (condition) { code to be executed if condition is true; }
  • 2. Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood 2 The example below will output "Have a good day!" if the current time (HOUR) is less than 20: Example <?php $t = date("H"); if ($t < "20") { echo "Have a good day!"; } ?> 2. PHP - The if...else Statement The if....else statement executes some code if a condition is true and another code if that condition is false. Syntax if (condition) { code to be executed if condition is true; } else { code to be executed if condition is false; } The example below will output "Have a good day!" if the current time is less than 20, and "Have a good night!" otherwise: Example <?php $t = date("H"); if ($t < "20") { echo "Have a good day!";
  • 3. Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood 3 } else { echo "Have a good night!"; } ?> 3. PHP - The if...elseif....else Statement The if....elseif...else statement executes different codes for more than two conditions. Syntax if (condition) { code to be executed if this condition is true; } elseif (condition) { code to be executed if this condition is true; } else { code to be executed if all conditions are false; } The example below will 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!": Example <?php $t = date("H"); if ($t < "10") { echo "Have a good morning!"; } elseif ($t < "20") { echo "Have a good day!"; } else {
  • 4. Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood 4 echo "Have a good night!"; } ?> 4. The PHP switch Statement Use the switch statement to select one of many blocks of code to be executed. Syntax switch (n) { case label1: code to be executed if n=label1; break; case label2: code to be executed if n=label2; break; case label3: code to be executed if n=label3; break; ... default: code to be executed if n is different from all labels; } This is how it works: First we have a single expression n (most often a variable), that is evaluated once. The value of the expression is then compared with the values for each case in the structure. If there is a match, the block of code associated with that case is executed. Use break to prevent the code from running into the next case automatically. The default statement is used if no match is found. Example <?php $favcolor = "red";
  • 5. Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood 5 switch ($favcolor) { case "red": echo "Your favorite color is red!"; break; case "blue": echo "Your favorite color is blue!"; break; case "green": echo "Your favorite color is green!"; break; default: echo "Your favorite color is neither red, blue, nor green!"; } ?> 5.PHP while Loops The while loop executes a block of code as long as the specified condition is true. Syntax while (condition is true) { code to be executed; } The example below first sets a variable $x to 1 ($x = 1). Then, the while loop will continue to run as long as $x is less than, or equal to 5 ($x <= 5). $x will increase by 1 each time the loop runs ($x++): Example <?php $x = 1;
  • 6. Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood 6 while($x <= 5) { echo "The number is: $x <br>"; $x++; } ?> 6. The PHP do...while Loop The do...while loop will always execute the block of code once, it will then check the condition, and repeat the loop while the specified condition is true. Syntax do { code to be executed; } while (condition is true); The example below first sets a variable $x to 1 ($x = 1). Then, the do while loop will write some output, and then increment the variable $x with 1. Then the condition is checked (is $x less than, or equal to 5?), and the loop will continue to run as long as $x is less than, or equal to 5: Example <?php $x = 1; do {
  • 7. Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood 7 echo "The number is: $x <br>"; $x++; } while ($x <= 5); ?> 7. The PHP for Loop The for loop is used when you know in advance how many times the script should run. Syntax for (init counter; test counter; increment counter) { code to be executed; } Parameters: •init counter: Initialize the loop counter value •test counter: Evaluated for each loop iteration. If it evaluates to TRUE, the loop continues. If it evaluates to FALSE, the loop ends. •increment counter: Increases the loop counter value The example below displays the numbers from 0 to 10: Example <?php for ($x = 0; $x <= 10; $x++) { echo "The number is: $x <br>";
  • 8. Subject: Web Design and Programming Lecturer: Ahmed Ali Saihood 8 } ?> 8. The PHP foreach Loop The foreach loop works only on arrays, and is used to loop through each key/value pair in an array. Syntax foreach ($array as $value) { code to be executed; } For every loop iteration, the value of the current array element is assigned to $value and the array pointer is moved by one, until it reaches the last array element. The following example demonstrates a loop that will output the values of the given array ($colors): Example <?php $colors = array("red", "green", "blue", "yellow"); foreach ($colors as $value) { echo "$value <br>"; } ?>