SlideShare une entreprise Scribd logo
1  sur  15
PHP Loops - Statements that enable you to achieve repetitive tasks.
The while Statement The 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 Statement A 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 />"; $num++; } while ( $num > 200 && $num < 400 ); ?>
The for Statement is 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 <?php for ( $counter=1; $counter<=12; $counter++ ) { print "$counter times 2 is".($counter*2)."<br />"; } ?>
Array An 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 time are 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 Arrays In 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 Functions is 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 <?php function myname(){ 	$name = "your-name"; echo "$name  <br />"; } echo "My Name is <br />"; myname(); ?>
A Function That Returns a Value A 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 <?php function addNums( $firstnum, $secondnum ) {  $result = $firstnum + $secondnum;   return $result;  }  print addNums(3,5);  // will print "8" ?>

Contenu connexe

Tendances

Php tutorial
Php tutorialPhp tutorial
Php tutorial
Niit
 

Tendances (20)

Php basics
Php basicsPhp basics
Php basics
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
PHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet SolutionPHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet Solution
 
php basics
php basicsphp basics
php basics
 
PHP slides
PHP slidesPHP slides
PHP slides
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Php introduction
Php introductionPhp introduction
Php introduction
 
PHP
PHPPHP
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)
 
PHP Comprehensive Overview
PHP Comprehensive OverviewPHP Comprehensive Overview
PHP Comprehensive Overview
 
Php introduction and configuration
Php introduction and configurationPhp introduction and configuration
Php introduction and configuration
 
PHP tutorial | ptutorial
PHP tutorial | ptutorialPHP tutorial | ptutorial
PHP tutorial | ptutorial
 
PHP MySQL Workshop - facehook
PHP MySQL Workshop - facehookPHP MySQL Workshop - facehook
PHP MySQL Workshop - facehook
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Php, mysq lpart1
Php, mysq lpart1Php, mysq lpart1
Php, mysq lpart1
 
Dev traning 2016 basics of PHP
Dev traning 2016   basics of PHPDev traning 2016   basics of PHP
Dev traning 2016 basics of PHP
 
Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
 
Class 6 - PHP Web Programming
Class 6 - PHP Web ProgrammingClass 6 - PHP Web Programming
Class 6 - PHP Web Programming
 

En vedette

Resumen de Inteligencia Emocional
Resumen de Inteligencia EmocionalResumen de Inteligencia Emocional
Resumen de Inteligencia Emocional
Alexandra Montesqo
 
Inteligencia emocional
Inteligencia emocionalInteligencia emocional
Inteligencia emocional
fanniilu
 
ما العلاقة بين قراءة سورة الكهف و فتنة المسيح الدجال‏
ما العلاقة بين قراءة سورة الكهف و فتنة المسيح الدجال‏ما العلاقة بين قراءة سورة الكهف و فتنة المسيح الدجال‏
ما العلاقة بين قراءة سورة الكهف و فتنة المسيح الدجال‏
amr hassaan
 
Reading vocabulary[1]
Reading vocabulary[1]Reading vocabulary[1]
Reading vocabulary[1]
Brenda Obando
 
Ebs performance tune2_con9030_pdf_9030_0002
Ebs performance tune2_con9030_pdf_9030_0002Ebs performance tune2_con9030_pdf_9030_0002
Ebs performance tune2_con9030_pdf_9030_0002
jucaab
 
Surgical guidelines article_2
Surgical guidelines article_2Surgical guidelines article_2
Surgical guidelines article_2
Ngô Định
 
Educational Technology Standards
Educational Technology StandardsEducational Technology Standards
Educational Technology Standards
mrbrdav
 
Sequence of events 1
Sequence of events 1Sequence of events 1
Sequence of events 1
Brenda Obando
 

En vedette (17)

Estructuras decision
Estructuras decisionEstructuras decision
Estructuras decision
 
Resumen de Inteligencia Emocional
Resumen de Inteligencia EmocionalResumen de Inteligencia Emocional
Resumen de Inteligencia Emocional
 
Circle area
Circle areaCircle area
Circle area
 
Talking About Race: Moving Toward a Transformative Dialogue
Talking About Race: Moving Toward a Transformative Dialogue Talking About Race: Moving Toward a Transformative Dialogue
Talking About Race: Moving Toward a Transformative Dialogue
 
Inteligencia emocional
Inteligencia emocionalInteligencia emocional
Inteligencia emocional
 
slideshare
slideshareslideshare
slideshare
 
Redes sociales presentacion
Redes sociales presentacionRedes sociales presentacion
Redes sociales presentacion
 
Second CRM A Business Introduction
Second CRM A Business IntroductionSecond CRM A Business Introduction
Second CRM A Business Introduction
 
ما العلاقة بين قراءة سورة الكهف و فتنة المسيح الدجال‏
ما العلاقة بين قراءة سورة الكهف و فتنة المسيح الدجال‏ما العلاقة بين قراءة سورة الكهف و فتنة المسيح الدجال‏
ما العلاقة بين قراءة سورة الكهف و فتنة المسيح الدجال‏
 
Global Warming Impact On Insurance Industry By Raj Trichy S
Global Warming   Impact On Insurance Industry   By Raj Trichy SGlobal Warming   Impact On Insurance Industry   By Raj Trichy S
Global Warming Impact On Insurance Industry By Raj Trichy S
 
Reading vocabulary[1]
Reading vocabulary[1]Reading vocabulary[1]
Reading vocabulary[1]
 
Ebs performance tune2_con9030_pdf_9030_0002
Ebs performance tune2_con9030_pdf_9030_0002Ebs performance tune2_con9030_pdf_9030_0002
Ebs performance tune2_con9030_pdf_9030_0002
 
Sequence
SequenceSequence
Sequence
 
Surgical guidelines article_2
Surgical guidelines article_2Surgical guidelines article_2
Surgical guidelines article_2
 
Educational Technology Standards
Educational Technology StandardsEducational Technology Standards
Educational Technology Standards
 
Sequence of events 1
Sequence of events 1Sequence of events 1
Sequence of events 1
 
Consequences of global warming and climate change
Consequences of global warming and climate changeConsequences of global warming and climate change
Consequences of global warming and climate change
 

Similaire à Php Loop

Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Course
mussawir20
 
Php Operators N Controllers
Php Operators N ControllersPhp Operators N Controllers
Php Operators N Controllers
mussawir20
 
P H P Part I, By Kian
P H P  Part  I,  By  KianP H P  Part  I,  By  Kian
P H P Part I, By Kian
phelios
 

Similaire à Php Loop (20)

What Is Php
What Is PhpWhat Is Php
What Is Php
 
Jquery 1
Jquery 1Jquery 1
Jquery 1
 
02 Php Vars Op Control Etc
02 Php Vars Op Control Etc02 Php Vars Op Control Etc
02 Php Vars Op Control Etc
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Course
 
Php
PhpPhp
Php
 
Php Operators N Controllers
Php Operators N ControllersPhp Operators N Controllers
Php Operators N Controllers
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
Web development
Web developmentWeb development
Web development
 
Babitha5.php
Babitha5.phpBabitha5.php
Babitha5.php
 
Php
PhpPhp
Php
 
Babitha5.php
Babitha5.phpBabitha5.php
Babitha5.php
 
Babitha5.php
Babitha5.phpBabitha5.php
Babitha5.php
 
P H P Part I, By Kian
P H P  Part  I,  By  KianP H P  Part  I,  By  Kian
P H P Part I, By Kian
 
Dealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottDealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter Scott
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
 
php programming.pptx
php programming.pptxphp programming.pptx
php programming.pptx
 
Basic PHP
Basic PHPBasic PHP
Basic PHP
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
PHP Tutorials
PHP TutorialsPHP Tutorials
PHP Tutorials
 

Plus de lotlot

Pseudocode-Flowchart
Pseudocode-FlowchartPseudocode-Flowchart
Pseudocode-Flowchart
lotlot
 
Form Script
Form ScriptForm Script
Form Script
lotlot
 
Mysql Aggregate
Mysql AggregateMysql Aggregate
Mysql Aggregate
lotlot
 
Mysql Script
Mysql ScriptMysql Script
Mysql Script
lotlot
 
Php Form
Php FormPhp Form
Php Form
lotlot
 
Php Condition Flow
Php Condition FlowPhp Condition Flow
Php Condition Flow
lotlot
 
Php-Continuation
Php-ContinuationPhp-Continuation
Php-Continuation
lotlot
 
Hariyali - India
Hariyali - IndiaHariyali - India
Hariyali - India
lotlot
 
The Province Of Davao Oriental
The Province Of Davao OrientalThe Province Of Davao Oriental
The Province Of Davao Oriental
lotlot
 
Annual Review
Annual ReviewAnnual Review
Annual Review
lotlot
 

Plus de lotlot (11)

Pseudocode-Flowchart
Pseudocode-FlowchartPseudocode-Flowchart
Pseudocode-Flowchart
 
Form Script
Form ScriptForm Script
Form Script
 
Mysql Aggregate
Mysql AggregateMysql Aggregate
Mysql Aggregate
 
Mysql Script
Mysql ScriptMysql Script
Mysql Script
 
Mysql
MysqlMysql
Mysql
 
Php Form
Php FormPhp Form
Php Form
 
Php Condition Flow
Php Condition FlowPhp Condition Flow
Php Condition Flow
 
Php-Continuation
Php-ContinuationPhp-Continuation
Php-Continuation
 
Hariyali - India
Hariyali - IndiaHariyali - India
Hariyali - India
 
The Province Of Davao Oriental
The Province Of Davao OrientalThe Province Of Davao Oriental
The Province Of Davao Oriental
 
Annual Review
Annual ReviewAnnual Review
Annual Review
 

Dernier

Dernier (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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
 
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...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

Php Loop

  • 1. PHP Loops - Statements that enable you to achieve repetitive tasks.
  • 2. The while Statement The 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 Statement A 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 />"; $num++; } while ( $num > 200 && $num < 400 ); ?>
  • 6. The for Statement is 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 <?php for ( $counter=1; $counter<=12; $counter++ ) { print "$counter times 2 is".($counter*2)."<br />"; } ?>
  • 8. Array An 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 time are 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 Arrays In 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 Functions is 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 <?php function myname(){ $name = "your-name"; echo "$name <br />"; } echo "My Name is <br />"; myname(); ?>
  • 14. A Function That Returns a Value A 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 <?php function addNums( $firstnum, $secondnum ) { $result = $firstnum + $secondnum; return $result; } print addNums(3,5); // will print "8" ?>