SlideShare une entreprise Scribd logo
1  sur  22
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

Contenu connexe

Tendances

Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5Twib in Yokoahma.pm 2010/3/5
Twib in Yokoahma.pm 2010/3/5
Yusuke Wada
 
Up.Php
Up.PhpUp.Php
Up.Php
wsoom
 
YAPC::Asia 2010 Twitter解析サービス
YAPC::Asia 2010 Twitter解析サービスYAPC::Asia 2010 Twitter解析サービス
YAPC::Asia 2010 Twitter解析サービス
Yusuke Wada
 
Programming For Designers V3
Programming For Designers V3Programming For Designers V3
Programming For Designers V3
sqoo
 

Tendances (20)

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

En vedette (11)

Php 2
Php 2Php 2
Php 2
 
Introduction to php 6
Introduction to php   6Introduction to php   6
Introduction to php 6
 
Php Condition Flow
Php Condition FlowPhp Condition Flow
Php Condition Flow
 
ppt on Segmentation in operationg system
ppt on Segmentation in operationg systemppt on Segmentation in operationg system
ppt on Segmentation in operationg system
 
Looping statement
Looping statementLooping statement
Looping statement
 
Form Script
Form ScriptForm Script
Form Script
 
Php Operators N Controllers
Php Operators N ControllersPhp Operators N Controllers
Php Operators N Controllers
 
Loops in C
Loops in CLoops in C
Loops in C
 
Mysql
MysqlMysql
Mysql
 
Php Form
Php FormPhp Form
Php Form
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
 

Similaire à Php modul-2

Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 

Similaire à Php modul-2 (20)

07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards
 
tutorial7
tutorial7tutorial7
tutorial7
 
tutorial7
tutorial7tutorial7
tutorial7
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
perl_lessons
perl_lessonsperl_lessons
perl_lessons
 
perl_lessons
perl_lessonsperl_lessons
perl_lessons
 
PHP_Lecture.pdf
PHP_Lecture.pdfPHP_Lecture.pdf
PHP_Lecture.pdf
 
What's New in Perl? v5.10 - v5.16
What's New in Perl?  v5.10 - v5.16What's New in Perl?  v5.10 - v5.16
What's New in Perl? v5.10 - v5.16
 
PHP-Overview.ppt
PHP-Overview.pptPHP-Overview.ppt
PHP-Overview.ppt
 
PHP-01-Overview.ppt
PHP-01-Overview.pptPHP-01-Overview.ppt
PHP-01-Overview.ppt
 
PHP variables
PHP  variablesPHP  variables
PHP variables
 
Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)
 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation Tutorial
 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6
 
Php Lecture Notes
Php Lecture NotesPhp Lecture Notes
Php Lecture Notes
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
Web 8 | Introduction to PHP
Web 8 | Introduction to PHPWeb 8 | Introduction to PHP
Web 8 | Introduction to PHP
 
Barcelona.pm Curs1211 sess01
Barcelona.pm Curs1211 sess01Barcelona.pm Curs1211 sess01
Barcelona.pm Curs1211 sess01
 

Dernier

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

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