SlideShare a Scribd company logo
Control Statement
PHP - TUTORIAL
Selection
● IF
● IF … ELSE
● ELSEIF
● SWITCH
Selection - IF
● IF <expression>
statement-true;
● ex.
$name=”kris”;
IF ($name==”kris”)
echo “Welcome Kris.”;
Selection – IF … ELSE
● IF <expression>
statement-true;
ELSE
statement-false;
Selection – IF … ELSE
● Ex.
$name=”Kris”;
IF ($name=”kris”)
echo “Welcome Kris.”;
ELSE
echo “You're not Kris.”;
Selection - ELSEIF
● IF <expression1>
statement-true1;
ELSEIF <expression2>
statement-true2;
ELSE
statement-false;
Selection - ELSEIF
$name=”John”;
IF ($name==”Kris”)
echo “Welcome Kris.”;
ELSEIF ($name==”John”)
echo “Welcome John.”;
Selection - Switch
Switch (variable) {
case <value1>:
statement-1;
break;
case <value2>:
statement-2;
break;
default:
statement-default;
break;
}
Selection - Switch
$destination=”Paris”;
switch ($destination) {
case “Tokyo”:
echo “Bring extra 1000 $US”;
break;
case “Egypt”:
echo “Bring bulletproof vests”;
break;
case “Paris”:
echo “Bring a camera”;
break;
default:
echo “Dont' bring anything”;
break;
}
Loop
● While
● Do While
● For
● Foreach
Loop - While
● While (expression-true) {
statement; }
● Ex.
$i=0;
While ($i<=10) {
echo $i . “<br />”;
$i++;
}
Loop – Do While
Do {
statement;
} while (expression);
Loop – Do While
$a=0;
do {
echo $a . “<br/>”;
} while ($a>0);
Loop - For
● For (start; stop; increment) {
statement;
}
● Ex.
For ($b=0; $b<=10; $b++) {
echo $b . “<br />”;
}
Loop – Foreach
● foreach ($array as $value){
statement;
}
● Ex.
$colors = array("red","green","blue","yellow");
foreach ($colors as $value) {
echo "$value <br>";
}
Function
● Is a block of code that can be executed
whenever we need it
● Function <name>(parameters) {
statement;
return
}
Simple function
function say() {
echo “Nice to meet you.”;
}
echo “Hello Kris, ”;
say();
Function with Parameters
function say($name) {
echo “<br />Nice to meet you, “. $name;
}
echo “Hello, John.”;
say(“John”);
Simple function
function say() {
echo “Nice to meet you.”;
}
echo “Hello Kris, ”;
say();
Function that returning values
function add($x, $y) {
$total = $x + $y;
return $total;
}
$num=0;
echo “My number is “ . $num . ”<br />”;
$num = add(5,6);
echo “Now, my number is “ . $num;
Excercise
1. Write a php program to determine which one is the biggest number
from 2 numbers
2. Write a php program to determine which one is the biggest number
from 3 numbers
3. Write a php program which can determine a number is odd or even
4. Write number from 1 to 20 with while, do while, and for
5. Write even number from 1 to 20 with while, do while, and for
6. Write odd number from 1 to 20 with while, do while, and for
Homework
● Write a php program to determine the letter grade from given number
input (hint: use a function to generate the letter grade)
● Add a function to exercise number 1, 2, and 3

More Related Content

PDF
Uncovering Iterators
PDF
IsTrue(true)?
PDF
TDC2015 Porto Alegre - Automate everything with Phing !
PDF
Darkmira Tour PHP 2016 - Automatizando Tarefas com Phing
PDF
Perl Fitxers i Directoris
TXT
PDF
Laravel the right way
PDF
Generating Power with Yield
Uncovering Iterators
IsTrue(true)?
TDC2015 Porto Alegre - Automate everything with Phing !
Darkmira Tour PHP 2016 - Automatizando Tarefas com Phing
Perl Fitxers i Directoris
Laravel the right way
Generating Power with Yield

What's hot (20)

PDF
Beginning web programming with PHP [PHP 101-02]
PDF
Laravel, the right way - PHPConference 2016
PPTX
Loop
PPT
Php Mysql
PDF
PowerCMS X
PDF
次世代版 PowerCMS 開発プロジェクトのご紹介
PDF
The Magic Of Tie
PDF
Path::Tiny
PDF
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
PDF
Twib in Yokoahma.pm 2010/3/5
XLS
Up.Php
PPTX
AngularJs , How it works
PDF
Phing - PHP Conference 2015
PDF
[2019] 아직도 돈 주고 DB 쓰나요? for Developer
PDF
Not Really PHP by the book
PDF
YAPC::Asia 2010 Twitter解析サービス
PPT
Programming For Designers V3
PDF
Random. Kinda.
PDF
Beginning web programming with PHP [PHP 101-02]
Laravel, the right way - PHPConference 2016
Loop
Php Mysql
PowerCMS X
次世代版 PowerCMS 開発プロジェクトのご紹介
The Magic Of Tie
Path::Tiny
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
Twib in Yokoahma.pm 2010/3/5
Up.Php
AngularJs , How it works
Phing - PHP Conference 2015
[2019] 아직도 돈 주고 DB 쓰나요? for Developer
Not Really PHP by the book
YAPC::Asia 2010 Twitter解析サービス
Programming For Designers V3
Random. Kinda.
Ad

Viewers also liked (11)

PPTX
Php 2
PPTX
Introduction to php 6
PPTX
Php Condition Flow
PPTX
ppt on Segmentation in operationg system
PPTX
Looping statement
PPTX
Form Script
PPT
Php Operators N Controllers
PPTX
Loops in C
PPTX
Mysql
PPTX
Php Form
PPT
Php Presentation
Php 2
Introduction to php 6
Php Condition Flow
ppt on Segmentation in operationg system
Looping statement
Form Script
Php Operators N Controllers
Loops in C
Mysql
Php Form
Php Presentation
Ad

Similar to Php modul-2 (20)

PDF
07 Introduction to PHP #burningkeyboards
PPT
PHP-01-Overview.pptfreeforeveryonecomenow
PPT
PHP - programing and pr155345345354553555
PDF
tutorial7
PDF
tutorial7
PPT
Introduction to php
PPT
PHP and MySQL
PDF
perl_lessons
PDF
perl_lessons
PPTX
PHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP n
PPT
PHP teaching ppt for the freshers in colleeg.ppt
PDF
PHP_Lecture.pdf
PDF
What's New in Perl? v5.10 - v5.16
PPT
PHP-Overview.ppt
PPTX
Data types and variables in php for writing
PPT
PHP-01-Overview.ppt
PPTX
data type in php and its introduction to use
PPT
PHP variables
PPTX
PHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP n
PDF
Learning Perl 6 (NPW 2007)
07 Introduction to PHP #burningkeyboards
PHP-01-Overview.pptfreeforeveryonecomenow
PHP - programing and pr155345345354553555
tutorial7
tutorial7
Introduction to php
PHP and MySQL
perl_lessons
perl_lessons
PHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP n
PHP teaching ppt for the freshers in colleeg.ppt
PHP_Lecture.pdf
What's New in Perl? v5.10 - v5.16
PHP-Overview.ppt
Data types and variables in php for writing
PHP-01-Overview.ppt
data type in php and its introduction to use
PHP variables
PHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP n
Learning Perl 6 (NPW 2007)

Recently uploaded (20)

PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Spectroscopy.pptx food analysis technology
Dropbox Q2 2025 Financial Results & Investor Presentation
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Building Integrated photovoltaic BIPV_UPV.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
The AUB Centre for AI in Media Proposal.docx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Network Security Unit 5.pdf for BCA BBA.
Review of recent advances in non-invasive hemoglobin estimation
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Programs and apps: productivity, graphics, security and other tools
Spectral efficient network and resource selection model in 5G networks
Diabetes mellitus diagnosis method based random forest with bat algorithm
A comparative analysis of optical character recognition models for extracting...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Spectroscopy.pptx food analysis technology

Php modul-2

  • 2. Selection ● IF ● IF … ELSE ● ELSEIF ● SWITCH
  • 3. Selection - IF ● IF <expression> statement-true; ● ex. $name=”kris”; IF ($name==”kris”) echo “Welcome Kris.”;
  • 4. Selection – IF … ELSE ● IF <expression> statement-true; ELSE statement-false;
  • 5. Selection – IF … ELSE ● Ex. $name=”Kris”; IF ($name=”kris”) echo “Welcome Kris.”; ELSE echo “You're not Kris.”;
  • 6. Selection - ELSEIF ● IF <expression1> statement-true1; ELSEIF <expression2> statement-true2; ELSE statement-false;
  • 7. Selection - ELSEIF $name=”John”; IF ($name==”Kris”) echo “Welcome Kris.”; ELSEIF ($name==”John”) echo “Welcome John.”;
  • 8. Selection - Switch Switch (variable) { case <value1>: statement-1; break; case <value2>: statement-2; break; default: statement-default; break; }
  • 9. Selection - Switch $destination=”Paris”; switch ($destination) { case “Tokyo”: echo “Bring extra 1000 $US”; break; case “Egypt”: echo “Bring bulletproof vests”; break; case “Paris”: echo “Bring a camera”; break; default: echo “Dont' bring anything”; break; }
  • 10. Loop ● While ● Do While ● For ● Foreach
  • 11. Loop - While ● While (expression-true) { statement; } ● Ex. $i=0; While ($i<=10) { echo $i . “<br />”; $i++; }
  • 12. Loop – Do While Do { statement; } while (expression);
  • 13. Loop – Do While $a=0; do { echo $a . “<br/>”; } while ($a>0);
  • 14. Loop - For ● For (start; stop; increment) { statement; } ● Ex. For ($b=0; $b<=10; $b++) { echo $b . “<br />”; }
  • 15. Loop – Foreach ● foreach ($array as $value){ statement; } ● Ex. $colors = array("red","green","blue","yellow"); foreach ($colors as $value) { echo "$value <br>"; }
  • 16. Function ● Is a block of code that can be executed whenever we need it ● Function <name>(parameters) { statement; return }
  • 17. Simple function function say() { echo “Nice to meet you.”; } echo “Hello Kris, ”; say();
  • 18. Function with Parameters function say($name) { echo “<br />Nice to meet you, “. $name; } echo “Hello, John.”; say(“John”);
  • 19. Simple function function say() { echo “Nice to meet you.”; } echo “Hello Kris, ”; say();
  • 20. Function that returning values function add($x, $y) { $total = $x + $y; return $total; } $num=0; echo “My number is “ . $num . ”<br />”; $num = add(5,6); echo “Now, my number is “ . $num;
  • 21. Excercise 1. Write a php program to determine which one is the biggest number from 2 numbers 2. Write a php program to determine which one is the biggest number from 3 numbers 3. Write a php program which can determine a number is odd or even 4. Write number from 1 to 20 with while, do while, and for 5. Write even number from 1 to 20 with while, do while, and for 6. Write odd number from 1 to 20 with while, do while, and for
  • 22. Homework ● Write a php program to determine the letter grade from given number input (hint: use a function to generate the letter grade) ● Add a function to exercise number 1, 2, and 3