SlideShare a Scribd company logo
3
Most read
4
Most read
11
Most read
Decision and
looping examples
with PHP
Kunjan Shah
TY CE 2
Batch C
170410107103
Introduction to PHP
PHP stands for Hypertext Preprocessor.
PHP is a server side scripting languages that allows you to
create dynamic web pages.
It is free to download and use.
You can embed PHP scripting within normal html coding.
 It is mainly used for form handling and database access.
The extension to the PHP files are .php, .php3 or .phtml and
.php4 as well.
Basics of PHP
 PHP code is contained within tags
<?php ?> or
short open: <? ?>
 PHP with HTML
echo is a command in PHP for writing output data to the browser, and at the end of each
PHP statement we require to write a ; (semicolon) as you see in the below example code.
Otherwise, if you write another statement, then PHP will report a syntax error.
<?php echo "Hello World"; ?> </body>
 Comments
// for single line
/* */ for multiline
DECISION MAKING STATMENTS
 The if, elseif ...else and switch statements are used to take decision based
on the different condition.
 You can use conditional statements in your code to make your decisions.
 PHP if..else statement:
 PHP if statement is used to execute some code, if a condition is evaluated
to true otherwise if the condition is evaluated to false, execute nothing, or
execute some other code.
The If...Else Statement
The ElseIf Statement
If you want to execute some code if one of the several conditions are true use the
elseif statement
The Switch Statement
 If you want to select one of many blocks of code to be executed, use the Switch
statement.
 The switch statement is used to avoid long blocks of if..elseif..else code.
 The switch statement works in an unusual way. First it evaluates given expression then
seeks a label to match the resulting value. If a matching value is found then the code
associated with the matching label will be executed or if none of the label matches then
statement will execute any specified default code.
The Switch Statement
Looping Statements
 Loops in PHP are used to execute the same block of code a specified number of
times. PHP supports following four loop types.
 for − loops through a block of code a specified number of times.
 while − loops through a block of code if and as long as a specified condition is
true.
 do...while − loops through a block of code once, and then repeats the loop as
long as a special condition is true.
 foreach − loops through a block of code for each element in an array.
The for loop statement
The while loop statement
The do...while loop statement
The foreach loop statement
 The foreach statement is used to loop through arrays. It loops over the array, and
each value for the current array element is assigned to $value, and the array
pointer is advanced by one to go the next element in the array.
The foreach loop statement
Decision and looping examples with php (WT)

More Related Content

PDF
I. Alpha-Beta Pruning in ai
PPTX
OOP Introduction with java programming language
PPTX
Inheritance in java
PPT
JAVA Polymorphism
PPTX
heap Sort Algorithm
PPTX
AI_Session 11: searching with Non-Deterministic Actions and partial observati...
PPTX
Function overloading and overriding
PDF
C++ interview question
I. Alpha-Beta Pruning in ai
OOP Introduction with java programming language
Inheritance in java
JAVA Polymorphism
heap Sort Algorithm
AI_Session 11: searching with Non-Deterministic Actions and partial observati...
Function overloading and overriding
C++ interview question

What's hot (20)

PDF
Race conditions
PPTX
Polymorphism presentation in java
PPTX
closure properties of regular language.pptx
PPTX
Final keyword in java
PPTX
Local beam search example
PDF
Compiler unit 5
PPTX
Operating system paging and segmentation
PPT
Introduction to method overloading &amp; method overriding in java hdm
PPT
Concurrency
PPTX
Hill climbing algorithm
PDF
Big Data technology Landscape
PPTX
Chapter 07 inheritance
PPTX
Exception handling in Python
PPTX
AI: Logic in AI
PPTX
Informed search algorithms.pptx
PDF
Python for Data Science | Python Data Science Tutorial | Data Science Certifi...
PPTX
OOP Unit 2 - Classes and Object
PPTX
Lecture 17 Iterative Deepening a star algorithm
PPTX
Strings in Java
Race conditions
Polymorphism presentation in java
closure properties of regular language.pptx
Final keyword in java
Local beam search example
Compiler unit 5
Operating system paging and segmentation
Introduction to method overloading &amp; method overriding in java hdm
Concurrency
Hill climbing algorithm
Big Data technology Landscape
Chapter 07 inheritance
Exception handling in Python
AI: Logic in AI
Informed search algorithms.pptx
Python for Data Science | Python Data Science Tutorial | Data Science Certifi...
OOP Unit 2 - Classes and Object
Lecture 17 Iterative Deepening a star algorithm
Strings in Java
Ad

Similar to Decision and looping examples with php (WT) (20)

PDF
PHP Basic & Variables
PPTX
Basic of PHP
PDF
Php introduction
PDF
1336333055 php tutorial_from_beginner_to_master
PPT
PHP - Introduction to PHP - Mazenet Solution
DOC
PHP MATERIAL
PPTX
PDF
Programming in PHP Course Material BCA 6th Semester
PPT
Php i-slides
PPT
Php i-slides
PPT
Php i-slides
PPT
Php i-slides (2) (1)
PPT
php41.ppt
PPT
PHP InterLevel.ppt
PPT
php-I-slides.ppt
PDF
Php tutorial from_beginner_to_master
PDF
PPT
introduction to php web programming 2024.ppt
PPSX
PHP Comprehensive Overview
PHP Basic & Variables
Basic of PHP
Php introduction
1336333055 php tutorial_from_beginner_to_master
PHP - Introduction to PHP - Mazenet Solution
PHP MATERIAL
Programming in PHP Course Material BCA 6th Semester
Php i-slides
Php i-slides
Php i-slides
Php i-slides (2) (1)
php41.ppt
PHP InterLevel.ppt
php-I-slides.ppt
Php tutorial from_beginner_to_master
introduction to php web programming 2024.ppt
PHP Comprehensive Overview
Ad

More from kunjan shah (6)

PPTX
Error detection techniques
PPTX
Multidimensional schema of data warehouse
PPTX
Dynamic storage allocation techniques in Compiler design
PPT
season management in php (WT)
PPTX
Web browser and web servers (WT)
PPTX
Generic view of software engineering SE
Error detection techniques
Multidimensional schema of data warehouse
Dynamic storage allocation techniques in Compiler design
season management in php (WT)
Web browser and web servers (WT)
Generic view of software engineering SE

Recently uploaded (20)

DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
PPT on Performance Review to get promotions
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
Digital Logic Computer Design lecture notes
PDF
Well-logging-methods_new................
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
additive manufacturing of ss316l using mig welding
PPTX
UNIT 4 Total Quality Management .pptx
PDF
composite construction of structures.pdf
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPT on Performance Review to get promotions
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Foundation to blockchain - A guide to Blockchain Tech
CYBER-CRIMES AND SECURITY A guide to understanding
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Automation-in-Manufacturing-Chapter-Introduction.pdf
Model Code of Practice - Construction Work - 21102022 .pdf
Digital Logic Computer Design lecture notes
Well-logging-methods_new................
bas. eng. economics group 4 presentation 1.pptx
additive manufacturing of ss316l using mig welding
UNIT 4 Total Quality Management .pptx
composite construction of structures.pdf

Decision and looping examples with php (WT)

  • 1. Decision and looping examples with PHP Kunjan Shah TY CE 2 Batch C 170410107103
  • 2. Introduction to PHP PHP stands for Hypertext Preprocessor. PHP is a server side scripting languages that allows you to create dynamic web pages. It is free to download and use. You can embed PHP scripting within normal html coding.  It is mainly used for form handling and database access. The extension to the PHP files are .php, .php3 or .phtml and .php4 as well.
  • 3. Basics of PHP  PHP code is contained within tags <?php ?> or short open: <? ?>  PHP with HTML echo is a command in PHP for writing output data to the browser, and at the end of each PHP statement we require to write a ; (semicolon) as you see in the below example code. Otherwise, if you write another statement, then PHP will report a syntax error. <?php echo "Hello World"; ?> </body>  Comments // for single line /* */ for multiline
  • 4. DECISION MAKING STATMENTS  The if, elseif ...else and switch statements are used to take decision based on the different condition.  You can use conditional statements in your code to make your decisions.  PHP if..else statement:  PHP if statement is used to execute some code, if a condition is evaluated to true otherwise if the condition is evaluated to false, execute nothing, or execute some other code.
  • 6. The ElseIf Statement If you want to execute some code if one of the several conditions are true use the elseif statement
  • 7. The Switch Statement  If you want to select one of many blocks of code to be executed, use the Switch statement.  The switch statement is used to avoid long blocks of if..elseif..else code.  The switch statement works in an unusual way. First it evaluates given expression then seeks a label to match the resulting value. If a matching value is found then the code associated with the matching label will be executed or if none of the label matches then statement will execute any specified default code.
  • 9. Looping Statements  Loops in PHP are used to execute the same block of code a specified number of times. PHP supports following four loop types.  for − loops through a block of code a specified number of times.  while − loops through a block of code if and as long as a specified condition is true.  do...while − loops through a block of code once, and then repeats the loop as long as a special condition is true.  foreach − loops through a block of code for each element in an array.
  • 10. The for loop statement
  • 11. The while loop statement
  • 12. The do...while loop statement
  • 13. The foreach loop statement  The foreach statement is used to loop through arrays. It loops over the array, and each value for the current array element is assigned to $value, and the array pointer is advanced by one to go the next element in the array.
  • 14. The foreach loop statement