SlideShare a Scribd company logo
PHP Language Operators & Control Structures
Switch-case() statement Switch (decision-variable) { case first condition is true: do this! case second condition is true: do this! . . . …  and so on … }
Appropriate case() block execution Depend on the value of decision variable Default block Decision variable not match any of the listed case() conditions
Example <?php // get form selection $day  =  $_GET [ 'day' ]; // check value and select appropriate item switch ( $day ) {     case  1 :          $special  =  'Chicken in oyster sauce' ;         break;     case  2 :          $special  =  'French onion soup' ;         break;     case  3 :          $special  =  'Pork chops with mashed potatoes and green salad' ;         break;     default:          $special  =  'Fish and chips' ;         break; } ?> <h2>Today's special is:</h2> <?php  echo  $special ?> </body> </html>
While() loop While (condition is true) { do this! }
Execution of php statements within curly braces As long as the specified condition is true Condition becomes false The loop will be broken and the following statement will be executed.
Examples <?php $number = 5; while   ($number  >= 2 ) { echo  $number.  &quot;<br/>&quot;  ; $number - = 1; } ?>
Examples Variable is initialized to 5 The while loop executes as long as the condition, ($number>=2) is true At the end of the loop block, the value of $number is decreased by 1.
Output of example
The while() loop executes a set of statements while a specified condition is true. But what happens if the condition is true on the first iteration of the loop itself? If you're in a situation where you need to execute a set of statements *at least* once, PHP offers you the do-while() loop.
Do-while() statement do {     do this! } while (condition is true)
While() vs do-while() Let's take a quick example to better understand the difference between while() and do-while():
Examples <?php $x  =  100 ; // while loop while ( $x  ==  700 ) {     echo  &quot;Running...&quot; ;     break; } ?>
In this case, no matter how many times you run this PHP script, you will get no output at all, since the value of $x is not equal to 700. But, if you ran this version of the script:
Example <?php $x  =  100 ; // do-while loop do {     echo  &quot;Running...&quot; ;     break; } while ( $x  ==  700 ); ?>
you would see  one  line of output, as the code within the do() block would run once.
<html> <head></head> <body> <?php // set variables from form input $upperLimit  =  $_POST [ 'limit' ]; $lowerLimit  =  1 ; // keep printing squares until lower limit = upper limit do {     echo ( $lowerLimit  *  $lowerLimit ). '&nbsp;' ;      $lowerLimit ++; } while ( $lowerLimit  <=  $upperLimit ); // print end marker echo  ' END' ; ?> </body> </html>
Thus, the construction of the do-while() loop is such that the statements within the loop are executed first, and the condition to be tested is checked afterwards. This implies that the statements within the curly braces would be executed at least once.
For() loops Both the while() and do-while() loops continue to iterate for as long as the specified conditional expression remains true. But what if you need to execute a certain set of statements a specific number of times - for example, printing a series of thirteen sequential numbers, or repeating a particular set of <td> cells five times? In such cases, clever programmers reach for the for() loop...
The for() loop typically looks like this:  for (initial value of counter; condition; new value of counter) {     do this! }
Examples <html> <head> <basefont face=&quot;Arial&quot;> </head> <body> <?php // define the number $number  =  13 ; // use a for loop to calculate tables for that number for ( $x  =  1 ;  $x  <=  10 ;  $x ++) {     echo  &quot;$number x $x = &quot; .( $number  *  $x ). &quot;<br />&quot; ; } ?> </body> </html>
define the number to be used for the multiplication table.  constructed a for() loop with $x as the counter variable, initialized it to 1.  specified that the loop should run no more than 10 times.  The auto-increment operator  automatically increments the counter by 1 every time the loop is executed. Within the loop, the counter is multiplied by the number,  to create the multiplication table, and echo() is used to display the result on the page.
Summary It is often desirable when writing code to perform different actions based on different decision. In addition to the if Statements, PHP includes a fourth type of conditional statement called the  switch  statement. The switch Statement is very similar or an alternative to the if...else if...else commands. The switch statement will test a condition. The outcome of that test will decide which case to execute. Switch is normally used when you are finding an exact (equal) result instead of a greater or less than result. When testing a range of values, the if statement should be used.
Summary In programming it is often necessary to repeat the same block of code a number of times. This can be accomplished using looping statements. PHP includes several types of looping statements.  The  while  statement loops through a block of code as long as a specified condition is evaluated as true. In other words, the while statement will execute a block of code if and as long as a condition is true.
Summary The  do...while  statement loops through a block of code as long as a specified condition is evaluated as true. In other words, the while statement will execute a block of code if and as long as a condition is true. The  do...while  loop is similar in nature to the  While  loop. The key difference is that the  do...while  loop body is guaranteed to run at least once. This is possible because the condition statement is evaluated at the end of the loop statement after the loop body is performed.
Summary The  for  statement loop is used when you know how many times you want to execute a statement or a list of statements. For this reason, the  for  loop is known as a definite loop.
<html> <head></head> <body> <?php // get form selection $day  =  $_GET [ 'day' ]; // check value and select appropriate item switch ( $day ) {     case  1 :          $special  =  'Chicken in oyster sauce' ;         break;     case  2 :          $special  =  'French onion soup' ;         break;     case  3 :          $special  =  'Pork chops with mashed potatoes and green salad' ;         break;     default:          $special  =  'Fish and chips' ;         break; } ?> <h2>Today's special is:</h2> <?php  echo  $special ?> </body> </html>
Ad

More Related Content

What's hot (20)

PHP variables
PHP  variablesPHP  variables
PHP variables
Siddique Ibrahim
 
Intermediate PHP
Intermediate PHPIntermediate PHP
Intermediate PHP
Bradley Holt
 
PHP Tips for certification - OdW13
PHP Tips for certification - OdW13PHP Tips for certification - OdW13
PHP Tips for certification - OdW13
julien pauli
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
Ian Macali
 
Data Types In PHP
Data Types In PHPData Types In PHP
Data Types In PHP
Mark Niebergall
 
PHP7. Game Changer.
PHP7. Game Changer. PHP7. Game Changer.
PHP7. Game Changer.
Haim Michael
 
Php Rss
Php RssPhp Rss
Php Rss
mussawir20
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requirePHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and require
TheCreativedev Blog
 
PHP Introduction and Training Material
PHP Introduction and Training MaterialPHP Introduction and Training Material
PHP Introduction and Training Material
Manoj kumar
 
Lecture 2 php basics (1)
Lecture 2  php basics (1)Lecture 2  php basics (1)
Lecture 2 php basics (1)
Core Lee
 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation Tutorial
Lorna Mitchell
 
PHP Basic
PHP BasicPHP Basic
PHP Basic
Yoeung Vibol
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!
omprakash_bagrao_prdxn
 
slidesharenew1
slidesharenew1slidesharenew1
slidesharenew1
truptitasol
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
Bhaktaraz Bhatta
 
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
anshkhurana01
 
PHP
PHPPHP
PHP
Rowena LI
 
Php Basic
Php BasicPhp Basic
Php Basic
Md. Sirajus Salayhin
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHP
Wim Godden
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
Ahmed Swilam
 
PHP Tips for certification - OdW13
PHP Tips for certification - OdW13PHP Tips for certification - OdW13
PHP Tips for certification - OdW13
julien pauli
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
Ian Macali
 
PHP7. Game Changer.
PHP7. Game Changer. PHP7. Game Changer.
PHP7. Game Changer.
Haim Michael
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and requirePHP - DataType,Variable,Constant,Operators,Array,Include and require
PHP - DataType,Variable,Constant,Operators,Array,Include and require
TheCreativedev Blog
 
PHP Introduction and Training Material
PHP Introduction and Training MaterialPHP Introduction and Training Material
PHP Introduction and Training Material
Manoj kumar
 
Lecture 2 php basics (1)
Lecture 2  php basics (1)Lecture 2  php basics (1)
Lecture 2 php basics (1)
Core Lee
 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation Tutorial
Lorna Mitchell
 
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
anshkhurana01
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHP
Wim Godden
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
Ahmed Swilam
 

Similar to Php Operators N Controllers (20)

Looping statement
Looping statementLooping statement
Looping statement
ilakkiya
 
What Is Php
What Is PhpWhat Is Php
What Is Php
AVC
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
aprilyyy
 
03loop conditional statements
03loop conditional statements03loop conditional statements
03loop conditional statements
Abdul Samad
 
Php Loop
Php LoopPhp Loop
Php Loop
lotlot
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
ChaAstillas
 
C++ programming
C++ programmingC++ programming
C++ programming
viancagerone
 
C++ programming
C++ programmingC++ programming
C++ programming
viancagerone
 
Switch case and looping jam
Switch case and looping jamSwitch case and looping jam
Switch case and looping jam
JamaicaAubreyUnite
 
PHP CONDITIONAL STATEMENTS AND LOOPING.ppt
PHP CONDITIONAL STATEMENTS AND LOOPING.pptPHP CONDITIONAL STATEMENTS AND LOOPING.ppt
PHP CONDITIONAL STATEMENTS AND LOOPING.ppt
rehna9
 
advancing in php programming part four.pptx
advancing in php programming part four.pptxadvancing in php programming part four.pptx
advancing in php programming part four.pptx
KisakyeDennis
 
Lesson 6 php if...else...elseif statements
Lesson 6   php if...else...elseif statementsLesson 6   php if...else...elseif statements
Lesson 6 php if...else...elseif statements
MLG College of Learning, Inc
 
Switch case and looping kim
Switch case and looping kimSwitch case and looping kim
Switch case and looping kim
kimberly_Bm10203
 
Switch case and looping new
Switch case and looping newSwitch case and looping new
Switch case and looping new
aprilyyy
 
Macasu, gerrell c.
Macasu, gerrell c.Macasu, gerrell c.
Macasu, gerrell c.
gerrell
 
PHP MATERIAL
PHP MATERIALPHP MATERIAL
PHP MATERIAL
zatax
 
Web Application Development using PHP Chapter 2
Web Application Development using PHP Chapter 2Web Application Development using PHP Chapter 2
Web Application Development using PHP Chapter 2
Mohd Harris Ahmad Jaal
 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)
jewelyngrace
 
CPAP.com Introduction To Coding: Part 2
CPAP.com Introduction To Coding: Part 2CPAP.com Introduction To Coding: Part 2
CPAP.com Introduction To Coding: Part 2
johnnygoodman
 
Janakiram web
Janakiram webJanakiram web
Janakiram web
MARELLA CHINABABU
 
Looping statement
Looping statementLooping statement
Looping statement
ilakkiya
 
What Is Php
What Is PhpWhat Is Php
What Is Php
AVC
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
aprilyyy
 
03loop conditional statements
03loop conditional statements03loop conditional statements
03loop conditional statements
Abdul Samad
 
Php Loop
Php LoopPhp Loop
Php Loop
lotlot
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
ChaAstillas
 
PHP CONDITIONAL STATEMENTS AND LOOPING.ppt
PHP CONDITIONAL STATEMENTS AND LOOPING.pptPHP CONDITIONAL STATEMENTS AND LOOPING.ppt
PHP CONDITIONAL STATEMENTS AND LOOPING.ppt
rehna9
 
advancing in php programming part four.pptx
advancing in php programming part four.pptxadvancing in php programming part four.pptx
advancing in php programming part four.pptx
KisakyeDennis
 
Switch case and looping kim
Switch case and looping kimSwitch case and looping kim
Switch case and looping kim
kimberly_Bm10203
 
Switch case and looping new
Switch case and looping newSwitch case and looping new
Switch case and looping new
aprilyyy
 
Macasu, gerrell c.
Macasu, gerrell c.Macasu, gerrell c.
Macasu, gerrell c.
gerrell
 
PHP MATERIAL
PHP MATERIALPHP MATERIAL
PHP MATERIAL
zatax
 
Web Application Development using PHP Chapter 2
Web Application Development using PHP Chapter 2Web Application Development using PHP Chapter 2
Web Application Development using PHP Chapter 2
Mohd Harris Ahmad Jaal
 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)
jewelyngrace
 
CPAP.com Introduction To Coding: Part 2
CPAP.com Introduction To Coding: Part 2CPAP.com Introduction To Coding: Part 2
CPAP.com Introduction To Coding: Part 2
johnnygoodman
 
Ad

More from mussawir20 (20)

Database Design Process
Database Design ProcessDatabase Design Process
Database Design Process
mussawir20
 
Php Simple Xml
Php Simple XmlPhp Simple Xml
Php Simple Xml
mussawir20
 
Php String And Regular Expressions
Php String  And Regular ExpressionsPhp String  And Regular Expressions
Php String And Regular Expressions
mussawir20
 
Php Sq Lite
Php Sq LitePhp Sq Lite
Php Sq Lite
mussawir20
 
Php Sessoins N Cookies
Php Sessoins N CookiesPhp Sessoins N Cookies
Php Sessoins N Cookies
mussawir20
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
mussawir20
 
Php Oop
Php OopPhp Oop
Php Oop
mussawir20
 
Php My Sql
Php My SqlPhp My Sql
Php My Sql
mussawir20
 
Php File Operations
Php File OperationsPhp File Operations
Php File Operations
mussawir20
 
Php Error Handling
Php Error HandlingPhp Error Handling
Php Error Handling
mussawir20
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Course
mussawir20
 
Php Basic Security
Php Basic SecurityPhp Basic Security
Php Basic Security
mussawir20
 
Php Using Arrays
Php Using ArraysPhp Using Arrays
Php Using Arrays
mussawir20
 
Javascript Oop
Javascript OopJavascript Oop
Javascript Oop
mussawir20
 
Html
HtmlHtml
Html
mussawir20
 
Javascript
JavascriptJavascript
Javascript
mussawir20
 
Object Range
Object RangeObject Range
Object Range
mussawir20
 
Prototype Utility Methods(1)
Prototype Utility Methods(1)Prototype Utility Methods(1)
Prototype Utility Methods(1)
mussawir20
 
Date
DateDate
Date
mussawir20
 
Prototype js
Prototype jsPrototype js
Prototype js
mussawir20
 
Database Design Process
Database Design ProcessDatabase Design Process
Database Design Process
mussawir20
 
Php Simple Xml
Php Simple XmlPhp Simple Xml
Php Simple Xml
mussawir20
 
Php String And Regular Expressions
Php String  And Regular ExpressionsPhp String  And Regular Expressions
Php String And Regular Expressions
mussawir20
 
Php Sessoins N Cookies
Php Sessoins N CookiesPhp Sessoins N Cookies
Php Sessoins N Cookies
mussawir20
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
mussawir20
 
Php File Operations
Php File OperationsPhp File Operations
Php File Operations
mussawir20
 
Php Error Handling
Php Error HandlingPhp Error Handling
Php Error Handling
mussawir20
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Course
mussawir20
 
Php Basic Security
Php Basic SecurityPhp Basic Security
Php Basic Security
mussawir20
 
Php Using Arrays
Php Using ArraysPhp Using Arrays
Php Using Arrays
mussawir20
 
Javascript Oop
Javascript OopJavascript Oop
Javascript Oop
mussawir20
 
Prototype Utility Methods(1)
Prototype Utility Methods(1)Prototype Utility Methods(1)
Prototype Utility Methods(1)
mussawir20
 
Ad

Recently uploaded (20)

Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Web and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in RajpuraWeb and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in Rajpura
Erginous Technology
 
Unlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive GuideUnlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive Guide
vikasascentbpo
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
MINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PRMINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PR
MIND CTI
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Web and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in RajpuraWeb and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in Rajpura
Erginous Technology
 
Unlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive GuideUnlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive Guide
vikasascentbpo
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
MINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PRMINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PR
MIND CTI
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 

Php Operators N Controllers

  • 1. PHP Language Operators & Control Structures
  • 2. Switch-case() statement Switch (decision-variable) { case first condition is true: do this! case second condition is true: do this! . . . … and so on … }
  • 3. Appropriate case() block execution Depend on the value of decision variable Default block Decision variable not match any of the listed case() conditions
  • 4. Example <?php // get form selection $day = $_GET [ 'day' ]; // check value and select appropriate item switch ( $day ) {     case 1 :          $special = 'Chicken in oyster sauce' ;         break;     case 2 :          $special = 'French onion soup' ;         break;     case 3 :          $special = 'Pork chops with mashed potatoes and green salad' ;         break;     default:          $special = 'Fish and chips' ;         break; } ?> <h2>Today's special is:</h2> <?php echo $special ?> </body> </html>
  • 5. While() loop While (condition is true) { do this! }
  • 6. Execution of php statements within curly braces As long as the specified condition is true Condition becomes false The loop will be broken and the following statement will be executed.
  • 7. Examples <?php $number = 5; while ($number >= 2 ) { echo $number. &quot;<br/>&quot; ; $number - = 1; } ?>
  • 8. Examples Variable is initialized to 5 The while loop executes as long as the condition, ($number>=2) is true At the end of the loop block, the value of $number is decreased by 1.
  • 10. The while() loop executes a set of statements while a specified condition is true. But what happens if the condition is true on the first iteration of the loop itself? If you're in a situation where you need to execute a set of statements *at least* once, PHP offers you the do-while() loop.
  • 11. Do-while() statement do {     do this! } while (condition is true)
  • 12. While() vs do-while() Let's take a quick example to better understand the difference between while() and do-while():
  • 13. Examples <?php $x = 100 ; // while loop while ( $x == 700 ) {     echo &quot;Running...&quot; ;     break; } ?>
  • 14. In this case, no matter how many times you run this PHP script, you will get no output at all, since the value of $x is not equal to 700. But, if you ran this version of the script:
  • 15. Example <?php $x = 100 ; // do-while loop do {     echo &quot;Running...&quot; ;     break; } while ( $x == 700 ); ?>
  • 16. you would see one line of output, as the code within the do() block would run once.
  • 17. <html> <head></head> <body> <?php // set variables from form input $upperLimit = $_POST [ 'limit' ]; $lowerLimit = 1 ; // keep printing squares until lower limit = upper limit do {     echo ( $lowerLimit * $lowerLimit ). '&nbsp;' ;      $lowerLimit ++; } while ( $lowerLimit <= $upperLimit ); // print end marker echo ' END' ; ?> </body> </html>
  • 18. Thus, the construction of the do-while() loop is such that the statements within the loop are executed first, and the condition to be tested is checked afterwards. This implies that the statements within the curly braces would be executed at least once.
  • 19. For() loops Both the while() and do-while() loops continue to iterate for as long as the specified conditional expression remains true. But what if you need to execute a certain set of statements a specific number of times - for example, printing a series of thirteen sequential numbers, or repeating a particular set of <td> cells five times? In such cases, clever programmers reach for the for() loop...
  • 20. The for() loop typically looks like this: for (initial value of counter; condition; new value of counter) {     do this! }
  • 21. Examples <html> <head> <basefont face=&quot;Arial&quot;> </head> <body> <?php // define the number $number = 13 ; // use a for loop to calculate tables for that number for ( $x = 1 ; $x <= 10 ; $x ++) {     echo &quot;$number x $x = &quot; .( $number * $x ). &quot;<br />&quot; ; } ?> </body> </html>
  • 22. define the number to be used for the multiplication table. constructed a for() loop with $x as the counter variable, initialized it to 1. specified that the loop should run no more than 10 times. The auto-increment operator automatically increments the counter by 1 every time the loop is executed. Within the loop, the counter is multiplied by the number, to create the multiplication table, and echo() is used to display the result on the page.
  • 23. Summary It is often desirable when writing code to perform different actions based on different decision. In addition to the if Statements, PHP includes a fourth type of conditional statement called the switch statement. The switch Statement is very similar or an alternative to the if...else if...else commands. The switch statement will test a condition. The outcome of that test will decide which case to execute. Switch is normally used when you are finding an exact (equal) result instead of a greater or less than result. When testing a range of values, the if statement should be used.
  • 24. Summary In programming it is often necessary to repeat the same block of code a number of times. This can be accomplished using looping statements. PHP includes several types of looping statements. The while statement loops through a block of code as long as a specified condition is evaluated as true. In other words, the while statement will execute a block of code if and as long as a condition is true.
  • 25. Summary The do...while statement loops through a block of code as long as a specified condition is evaluated as true. In other words, the while statement will execute a block of code if and as long as a condition is true. The do...while loop is similar in nature to the While loop. The key difference is that the do...while loop body is guaranteed to run at least once. This is possible because the condition statement is evaluated at the end of the loop statement after the loop body is performed.
  • 26. Summary The for statement loop is used when you know how many times you want to execute a statement or a list of statements. For this reason, the for loop is known as a definite loop.
  • 27. <html> <head></head> <body> <?php // get form selection $day = $_GET [ 'day' ]; // check value and select appropriate item switch ( $day ) {     case 1 :          $special = 'Chicken in oyster sauce' ;         break;     case 2 :          $special = 'French onion soup' ;         break;     case 3 :          $special = 'Pork chops with mashed potatoes and green salad' ;         break;     default:          $special = 'Fish and chips' ;         break; } ?> <h2>Today's special is:</h2> <?php echo $special ?> </body> </html>