SlideShare una empresa de 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" ?>

Más contenido relacionado

La actualidad más candente (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
 

Destacado

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
 

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

Similar 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
 

Similar 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
 

Más 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
 

Más 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

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 FresherRemote DBA Services
 
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 SavingEdi Saputra
 
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 productivityPrincipled Technologies
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
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...Miguel Araújo
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
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 DiscoveryTrustArc
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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 organizationRadu Cotescu
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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...Neo4j
 

Último (20)

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
 
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
 
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
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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...
 

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