SlideShare a Scribd company logo
PHPLoops - Statements that enable you to achieve repetitive tasks.
The while StatementThe while statement looks similar in structure to a basic if statement:	while ( expression ) { 	// do something 	}As long as a while statement's expression evaluates to true, the code block is executed repeatedly. Each execution of the code block in a loop is often called an iteration.
Sample 1<?php$counter = 1; while ( $counter <= 12 ) {print "Counter value is $counter"."<br />"; $counter++; } ?>
The do...while StatementA do...while statement looks a little like a while statement turned on its head. The essential difference between the two is that the code block is executed before the truth test and not after it.The test expression of a do...while statement should always end with a semicolon.do-while loop first do's and secondly checks the while condition!do { // code to be executed } while (expression);
Sample 2<?php$num = 1;do {print "Execution number: $num<br />\n";$num++;} while ( $num > 200 && $num < 400 );?>
The for Statementis simply a while loop with a bit more code added to it. The common tasks that are covered by a for loop are:Set a counter variable to some initial value.Check to see if the conditional statement is true.Execute the code within the loop.Increment a counter at the end of each iteration through the loop.for ( initialize a counter; conditional statement; increment a counter){do this code;}
Sample 3<?phpfor ( $counter=1; $counter<=12; $counter++ ) {print "$counter times 2 is".($counter*2)."<br />";}?>
ArrayAn array is a data structure that stores one or more values in a single value (bucket). The array() construct is useful when you want to assign multiple values to an array at one timeare indexed from zero by default, so the index of any element in a sequentially indexed array always is one less than the element's place in the list$users = array ("Bert", "Sharon", "Betty", "Harry");
Sample 4<?php//arrary$users = array ("Bert", "Sharon", "Betty", "Harry");print $users[2];?>
Associative ArraysIn an associative array a key is associated with a value.$salaries["Bob"] = 2000; $salaries["Sally"] = 4000; $salaries["Charlie"] = 600; $salaries["Clare"] = 0;
Sample 5<?php//associative arrary$salaries["Bob"] = 2000;$salaries["Sally"] = 4000;$salaries["Charlie"] = 600;$salaries["Clare"] = 0;echo "Bob is being paid - $" . $salaries["Bob"] . "<br />";echo "Sally is being paid - $" . $salaries["Sally"] . "<br />";echo "Charlie is being paid - $" . $salaries["Charlie"] . "<br />";echo "Clare is being paid - $" . $salaries["Clare"];?>
Php Functionsis a self-contained block of code that can be called by your scripts. When called, the function's code is executed. You can pass values to functions, which they then work with. When finished, a function can pass a value back to the calling code.function myCompanyMotto(){ 	//some codes	} ?>
Sample 6<?phpfunction myname(){	$name = "your-name";echo "$name  <br />";}echo "My Name is <br />";myname();?>
A Function That Returns a ValueA function can return a value using the return statement in conjunction with a value. return stops the execution of the function and sends the value back to the calling code.function addNums( $firstnum, $secondnum ) {$result = $firstnum + $secondnum; 	return $result; 	}
Sample 7<?phpfunction addNums( $firstnum, $secondnum ) { $result = $firstnum + $secondnum;  return $result; } print addNums(3,5); // will print "8"?>

More Related Content

What's hot (20)

Php basics
Php basics
Jamshid Hashimi
 
Basics PHP
Basics PHP
Alokin Software Pvt Ltd
 
Introduction to PHP
Introduction to PHP
Jussi Pohjolainen
 
PHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet Solution
Mazenetsolution
 
php basics
php basics
Anmol Paul
 
PHP slides
PHP slides
Farzad Wadia
 
Php Tutorial
Php Tutorial
Dr. Ramkumar Lakshminarayanan
 
Php introduction
Php introduction
krishnapriya Tadepalli
 
PHP
PHP
sometech
 
Php, mysq lpart4(processing html form)
Php, mysq lpart4(processing html form)
Subhasis Nayak
 
PHP Comprehensive Overview
PHP Comprehensive Overview
Mohamed Loey
 
Php introduction and configuration
Php introduction and configuration
Vijay Kumar Verma
 
PHP tutorial | ptutorial
PHP tutorial | ptutorial
PTutorial Web
 
PHP MySQL Workshop - facehook
PHP MySQL Workshop - facehook
Shashank Skills Academy
 
Php tutorial
Php tutorial
Niit
 
Introduction to php
Introduction to php
Meetendra Singh
 
Php, mysq lpart1
Php, mysq lpart1
Subhasis Nayak
 
Dev traning 2016 basics of PHP
Dev traning 2016 basics of PHP
Sacheen Dhanjie
 
Php and MySQL
Php and MySQL
Tiji Thomas
 
Class 6 - PHP Web Programming
Class 6 - PHP Web Programming
Ahmed Swilam
 

Viewers also liked (17)

Estructuras decision
Estructuras decision
Jose Guadalupe Noh Noh
 
Resumen de Inteligencia Emocional
Resumen de Inteligencia Emocional
Alexandra Montesqo
 
Circle area
Circle area
Brenda Obando
 
Talking About Race: Moving Toward a Transformative Dialogue
Talking About Race: Moving Toward a Transformative Dialogue
Kirwan Institute for the Study of Race and Ethnicity
 
Inteligencia emocional
Inteligencia emocional
fanniilu
 
slideshare
slideshare
guestf55d5cb3
 
Redes sociales presentacion
Redes sociales presentacion
LeidyDiazGonzalez
 
Second CRM A Business Introduction
Second CRM A Business Introduction
Soft Solvers Technologies
 
ما العلاقة بين قراءة سورة الكهف و فتنة المسيح الدجال‏
ما العلاقة بين قراءة سورة الكهف و فتنة المسيح الدجال‏
amr hassaan
 
Global Warming Impact On Insurance Industry By Raj Trichy S
Global Warming Impact On Insurance Industry By Raj Trichy S
ts_rajagopal
 
Reading vocabulary[1]
Reading vocabulary[1]
Brenda Obando
 
Ebs performance tune2_con9030_pdf_9030_0002
Ebs performance tune2_con9030_pdf_9030_0002
jucaab
 
Sequence
Sequence
Brenda Obando
 
Surgical guidelines article_2
Surgical guidelines article_2
Ngô Định
 
Educational Technology Standards
Educational Technology Standards
mrbrdav
 
Sequence of events 1
Sequence of events 1
Brenda Obando
 
Consequences of global warming and climate change
Consequences of global warming and climate change
St.Xavier's College , Palayamkottai - 627 002
 
Resumen de Inteligencia Emocional
Resumen de Inteligencia Emocional
Alexandra Montesqo
 
Inteligencia emocional
Inteligencia emocional
fanniilu
 
ما العلاقة بين قراءة سورة الكهف و فتنة المسيح الدجال‏
ما العلاقة بين قراءة سورة الكهف و فتنة المسيح الدجال‏
amr hassaan
 
Global Warming Impact On Insurance Industry By Raj Trichy S
Global Warming Impact On Insurance Industry By Raj Trichy S
ts_rajagopal
 
Reading vocabulary[1]
Reading vocabulary[1]
Brenda Obando
 
Ebs performance tune2_con9030_pdf_9030_0002
Ebs performance tune2_con9030_pdf_9030_0002
jucaab
 
Surgical guidelines article_2
Surgical guidelines article_2
Ngô Định
 
Educational Technology Standards
Educational Technology Standards
mrbrdav
 
Sequence of events 1
Sequence of events 1
Brenda Obando
 
Ad

Similar to Php Loop (20)

Php 2
Php 2
vivlinux
 
What Is Php
What Is Php
AVC
 
Php Chapter 1 Training
Php Chapter 1 Training
Chris Chubb
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
Ian Macali
 
Php Operators N Controllers
Php Operators N Controllers
mussawir20
 
Basic PHP
Basic PHP
Todd Barber
 
Php Basic
Php Basic
Md. Sirajus Salayhin
 
PHP Workshop Notes
PHP Workshop Notes
Pamela Fox
 
PHP Tutorials
PHP Tutorials
Yuriy Krapivko
 
PHP Tutorials
PHP Tutorials
Yuriy Krapivko
 
Php Crash Course
Php Crash Course
mussawir20
 
Php2
Php2
Keennary Pungyera
 
course slides -- powerpoint
course slides -- powerpoint
webhostingguy
 
Php Learning show
Php Learning show
Gnugroup India
 
PHP Lec 2.pdfsssssssssssssssssssssssssss
PHP Lec 2.pdfsssssssssssssssssssssssssss
ksjawyyy
 
Introduction To Php For Wit2009
Introduction To Php For Wit2009
cwarren
 
Looping statement
Looping statement
ilakkiya
 
PHP
PHP
webhostingguy
 
Web development
Web development
Seerat Bakhtawar
 
Php
Php
WAHEEDA ROOHILLAH
 
Ad

More from lotlot (11)

Pseudocode-Flowchart
Pseudocode-Flowchart
lotlot
 
Form Script
Form Script
lotlot
 
Mysql Aggregate
Mysql Aggregate
lotlot
 
Mysql Script
Mysql Script
lotlot
 
Mysql
Mysql
lotlot
 
Php Form
Php Form
lotlot
 
Php Condition Flow
Php Condition Flow
lotlot
 
Php-Continuation
Php-Continuation
lotlot
 
Hariyali - India
Hariyali - India
lotlot
 
The Province Of Davao Oriental
The Province Of Davao Oriental
lotlot
 
Annual Review
Annual Review
lotlot
 
Pseudocode-Flowchart
Pseudocode-Flowchart
lotlot
 
Form Script
Form Script
lotlot
 
Mysql Aggregate
Mysql Aggregate
lotlot
 
Mysql Script
Mysql Script
lotlot
 
Php Form
Php Form
lotlot
 
Php Condition Flow
Php Condition Flow
lotlot
 
Php-Continuation
Php-Continuation
lotlot
 
Hariyali - India
Hariyali - India
lotlot
 
The Province Of Davao Oriental
The Province Of Davao Oriental
lotlot
 
Annual Review
Annual Review
lotlot
 

Recently uploaded (20)

Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Safe Software
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
High Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdf
Safe Software
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
June Patch Tuesday
June Patch Tuesday
Ivanti
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Safe Software
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
High Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdf
Safe Software
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
June Patch Tuesday
June Patch Tuesday
Ivanti
 
Kubernetes Security Act Now Before It’s Too Late
Kubernetes Security Act Now Before It’s Too Late
Michael Furman
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 

Php Loop

  • 1. PHPLoops - Statements that enable you to achieve repetitive tasks.
  • 2. The while StatementThe while statement looks similar in structure to a basic if statement: while ( expression ) { // do something }As long as a while statement's expression evaluates to true, the code block is executed repeatedly. Each execution of the code block in a loop is often called an iteration.
  • 3. Sample 1<?php$counter = 1; while ( $counter <= 12 ) {print "Counter value is $counter"."<br />"; $counter++; } ?>
  • 4. The do...while StatementA do...while statement looks a little like a while statement turned on its head. The essential difference between the two is that the code block is executed before the truth test and not after it.The test expression of a do...while statement should always end with a semicolon.do-while loop first do's and secondly checks the while condition!do { // code to be executed } while (expression);
  • 5. Sample 2<?php$num = 1;do {print "Execution number: $num<br />\n";$num++;} while ( $num > 200 && $num < 400 );?>
  • 6. The for Statementis simply a while loop with a bit more code added to it. The common tasks that are covered by a for loop are:Set a counter variable to some initial value.Check to see if the conditional statement is true.Execute the code within the loop.Increment a counter at the end of each iteration through the loop.for ( initialize a counter; conditional statement; increment a counter){do this code;}
  • 7. Sample 3<?phpfor ( $counter=1; $counter<=12; $counter++ ) {print "$counter times 2 is".($counter*2)."<br />";}?>
  • 8. ArrayAn array is a data structure that stores one or more values in a single value (bucket). The array() construct is useful when you want to assign multiple values to an array at one timeare indexed from zero by default, so the index of any element in a sequentially indexed array always is one less than the element's place in the list$users = array ("Bert", "Sharon", "Betty", "Harry");
  • 9. Sample 4<?php//arrary$users = array ("Bert", "Sharon", "Betty", "Harry");print $users[2];?>
  • 10. Associative ArraysIn an associative array a key is associated with a value.$salaries["Bob"] = 2000; $salaries["Sally"] = 4000; $salaries["Charlie"] = 600; $salaries["Clare"] = 0;
  • 11. Sample 5<?php//associative arrary$salaries["Bob"] = 2000;$salaries["Sally"] = 4000;$salaries["Charlie"] = 600;$salaries["Clare"] = 0;echo "Bob is being paid - $" . $salaries["Bob"] . "<br />";echo "Sally is being paid - $" . $salaries["Sally"] . "<br />";echo "Charlie is being paid - $" . $salaries["Charlie"] . "<br />";echo "Clare is being paid - $" . $salaries["Clare"];?>
  • 12. Php Functionsis a self-contained block of code that can be called by your scripts. When called, the function's code is executed. You can pass values to functions, which they then work with. When finished, a function can pass a value back to the calling code.function myCompanyMotto(){ //some codes } ?>
  • 13. Sample 6<?phpfunction myname(){ $name = "your-name";echo "$name <br />";}echo "My Name is <br />";myname();?>
  • 14. A Function That Returns a ValueA function can return a value using the return statement in conjunction with a value. return stops the execution of the function and sends the value back to the calling code.function addNums( $firstnum, $secondnum ) {$result = $firstnum + $secondnum; return $result; }
  • 15. Sample 7<?phpfunction addNums( $firstnum, $secondnum ) { $result = $firstnum + $secondnum; return $result; } print addNums(3,5); // will print "8"?>