SlideShare uma empresa Scribd logo
1 de 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" ?>

Mais conteúdo relacionado

Mais procurados (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
 

Destaque

Resumen de Inteligencia Emocional
Resumen de Inteligencia EmocionalResumen de Inteligencia Emocional
Resumen de Inteligencia EmocionalAlexandra Montesqo
 
Inteligencia emocional
Inteligencia emocionalInteligencia emocional
Inteligencia emocionalfanniilu
 
ما العلاقة بين قراءة سورة الكهف و فتنة المسيح الدجال‏
ما العلاقة بين قراءة سورة الكهف و فتنة المسيح الدجال‏ما العلاقة بين قراءة سورة الكهف و فتنة المسيح الدجال‏
ما العلاقة بين قراءة سورة الكهف و فتنة المسيح الدجال‏amr hassaan
 
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 Sts_rajagopal
 
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_0002jucaab
 
Surgical guidelines article_2
Surgical guidelines article_2Surgical guidelines article_2
Surgical guidelines article_2Ngô Định
 
Educational Technology Standards
Educational Technology StandardsEducational Technology Standards
Educational Technology Standardsmrbrdav
 
Sequence of events 1
Sequence of events 1Sequence of events 1
Sequence of events 1Brenda Obando
 

Destaque (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
 

Semelhante a Php Loop

What Is Php
What Is PhpWhat Is Php
What Is PhpAVC
 
02 Php Vars Op Control Etc
02 Php Vars Op Control Etc02 Php Vars Op Control Etc
02 Php Vars Op Control EtcGeshan Manandhar
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Coursemussawir20
 
Php Operators N Controllers
Php Operators N ControllersPhp Operators N Controllers
Php Operators N Controllersmussawir20
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl TechniquesDave Cross
 
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 Kianphelios
 
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 ScottO'Reilly Media
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisIan Macali
 
php programming.pptx
php programming.pptxphp programming.pptx
php programming.pptxrani marri
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl TechniquesDave Cross
 

Semelhante a 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
 

Mais de lotlot

Pseudocode-Flowchart
Pseudocode-FlowchartPseudocode-Flowchart
Pseudocode-Flowchartlotlot
 
Form Script
Form ScriptForm Script
Form Scriptlotlot
 
Mysql Aggregate
Mysql AggregateMysql Aggregate
Mysql Aggregatelotlot
 
Mysql Script
Mysql ScriptMysql Script
Mysql Scriptlotlot
 
Php Form
Php FormPhp Form
Php Formlotlot
 
Php Condition Flow
Php Condition FlowPhp Condition Flow
Php Condition Flowlotlot
 
Php-Continuation
Php-ContinuationPhp-Continuation
Php-Continuationlotlot
 
Hariyali - India
Hariyali - IndiaHariyali - India
Hariyali - Indialotlot
 
The Province Of Davao Oriental
The Province Of Davao OrientalThe Province Of Davao Oriental
The Province Of Davao Orientallotlot
 
Annual Review
Annual ReviewAnnual Review
Annual Reviewlotlot
 

Mais 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
 

Último

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.pptxRustici Software
 
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 businesspanagenda
 
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...DianaGray10
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
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 FMESafe Software
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
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 TerraformAndrey Devyatkin
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
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, Adobeapidays
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
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 educationjfdjdjcjdnsjd
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 

Último (20)

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
 
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...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
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
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
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
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

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" ?>