SlideShare ist ein Scribd-Unternehmen logo
1 von 25
Conditional Statements In PHP we have the following conditional statements: ,[object Object]
if...else statement - use this statement to execute some code if a condition is true and another code if the condition is false
if...elseif....else statement - use this statement to select one of several blocks of code to be executed
switch statement - use this statement to select one of many blocks of code to be executed,[object Object]
The if...else Statement <?php$d=date("D");if ($d=="Fri")  echo "Have a nice weekend!";else  echo "Have a nice day!";?>
The if...elseif....else Statement <?php $d=date("D"); if ($d=="Fri")  echo "Have a nice weekend!"; elseif ($d=="Sun")  echo "Have a nice Sunday!"; else  echo "Have a nice day!"; ?>
Switch Statement <?phpswitch ($x){case 1:  echo "Number 1";  break;case 2:  echo "Number 2";  break;case 3:  echo "Number 3";  break;default:  echo "No number between 1 and 3";}?>
What is an Array? An array is a special variable, which can store multiple values in one single variable. There are three kind of arrays: ,[object Object]
Associative array - An array where each ID key is associated with a value
Multidimensional array - An array containing one or more arrays,[object Object]
Associative Arrays An associative array, each ID key is associated with a value. $ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34);  $ages['Peter'] = "32";$ages['Quagmire'] = "30";$ages['Joe'] = "34";
<?php$ages['Peter'] = "32";$ages['Quagmire'] = "30";$ages['Joe'] = "34";echo "Peter is " . $ages['Peter'] . " years old."; ?>
Multidimensional Arrays In a multidimensional array, each element in the main array can also be an array. And each element in the sub-array can be an array, and so on. $families = array  (  "Griffin"=>array  (  "Peter",  "Lois",  "Megan"  ),  "Quagmire"=>array  (  "Glenn"  ),  "Brown"=>array  (  "Cleveland",  "Loretta",  "Junior"  )  );
Array([Griffin] => Array  (  [0] => Peter  [1] => Lois  [2] => Megan  )[Quagmire] => Array  (  [0] => Glenn  )[Brown] => Array  (  [0] => Cleveland  [1] => Loretta  [2] => Junior  ))
Loops In PHP, we have the following looping statements: ,[object Object]
do...while - loops through a block of code once, and then repeats the loop as long as a specified condition is true
for - loops through a block of code a specified number of times
foreach- loops through a block of code for each element in an array,[object Object]
The do...while Statement The do...while statement will always execute the block of code once, it will then check the condition, and repeat the loop while the condition is true. <?php$i=1;do  {  $i++;  echo "The number is " . $i . "<br />";  }while ($i<=5);?>
The for Loop The for loop is used when you know in advance how many times the script should run. <?phpfor ($i=1; $i<=5; $i++)  {  echo "The number is " . $i . "<br />";  }?>
The foreach Loop The foreach loop is used to loop through arrays. <?php$x=array("one","two","three");foreach ($x as $value)  {  echo $value . "<br />";  }?>
Functions A function will be executed by a call to the function. <?phpfunction writeName(){echo "Kai Jim Refsnes";}echo "My name is ";writeName();?>
Functions - Adding parameters Parameters are specified after the function name, inside the parentheses. <?phpfunction writeName($fname){echo $fname . " Abraham.<br />";}echo "My name is ";writeName("Kai Jim");echo "My sister's name is ";writeName("Hege");echo "My brother's name is ";writeName("Stale");?>
Functions - Return values <?phpfunction add($x,$y){$total=$x+$y;return $total;} echo "1 + 16 = " . add(1,16); ?>
Using the break Statement 1: <?php 2: $counter = -4; 3: for (; $counter <= 10; $counter++) { 4: if ($counter == 0) { 5: break; 6: } else { 7: $temp = 4000/$counter; 8: echo “4000 divided by $counter is... $temp<br>”; 9: } 10: } 11 ?> By The Way Dividing a number by zero does not cause a fatal error in PHP. Instead, PHP generates a warning and execution continues. Did You Know? You can omit any of the expressions from a for statement, but you must remember to retain the separation semicolons.

Weitere ähnliche Inhalte

Was ist angesagt?

PHP7. Game Changer.
PHP7. Game Changer. PHP7. Game Changer.
PHP7. Game Changer. Haim Michael
 
From Zero to Iterators: Building and Extending the Iterator Hierarchy in a Mo...
From Zero to Iterators: Building and Extending the Iterator Hierarchy in a Mo...From Zero to Iterators: Building and Extending the Iterator Hierarchy in a Mo...
From Zero to Iterators: Building and Extending the Iterator Hierarchy in a Mo...Patrick Niedzielski
 
Achieving Parsing Sanity In Erlang
Achieving Parsing Sanity In ErlangAchieving Parsing Sanity In Erlang
Achieving Parsing Sanity In ErlangSean Cribbs
 
Perl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim PerlchinaPerl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim Perlchinaguestcf9240
 
Perl Xpath Lightning Talk
Perl Xpath Lightning TalkPerl Xpath Lightning Talk
Perl Xpath Lightning Talkddn123456
 
Maybe you do not know that ...
Maybe you do not know that ...Maybe you do not know that ...
Maybe you do not know that ...Viktor Turskyi
 
ScotRuby - Dark side of ruby
ScotRuby - Dark side of rubyScotRuby - Dark side of ruby
ScotRuby - Dark side of rubyGautam Rege
 
Using DAOs without implementing them
Using DAOs without implementing themUsing DAOs without implementing them
Using DAOs without implementing thembenfante
 
Cs hangman
Cs   hangmanCs   hangman
Cs hangmaniamkim
 
Round PEG, Round Hole - Parsing Functionally
Round PEG, Round Hole - Parsing FunctionallyRound PEG, Round Hole - Parsing Functionally
Round PEG, Round Hole - Parsing FunctionallySean Cribbs
 
Zen and the Art of Code Maintenance
Zen and the Art of Code MaintenanceZen and the Art of Code Maintenance
Zen and the Art of Code MaintenanceJemuel Young
 
The Perl API for the Mortally Terrified (beta)
The Perl API for the Mortally Terrified (beta)The Perl API for the Mortally Terrified (beta)
The Perl API for the Mortally Terrified (beta)Mike Friedman
 
Beautiful PHP CLI Scripts
Beautiful PHP CLI ScriptsBeautiful PHP CLI Scripts
Beautiful PHP CLI ScriptsJesse Donat
 
Make Your Own Perl with Moops
Make Your Own Perl with MoopsMake Your Own Perl with Moops
Make Your Own Perl with MoopsMike Friedman
 
Erlang/OTP for Rubyists
Erlang/OTP for RubyistsErlang/OTP for Rubyists
Erlang/OTP for RubyistsSean Cribbs
 
Rails for PHP Developers
Rails for PHP DevelopersRails for PHP Developers
Rails for PHP DevelopersRobert Dempsey
 
Ruby Topic Maps Tutorial (2007-10-10)
Ruby Topic Maps Tutorial (2007-10-10)Ruby Topic Maps Tutorial (2007-10-10)
Ruby Topic Maps Tutorial (2007-10-10)Benjamin Bock
 

Was ist angesagt? (20)

PHP7. Game Changer.
PHP7. Game Changer. PHP7. Game Changer.
PHP7. Game Changer.
 
From Zero to Iterators: Building and Extending the Iterator Hierarchy in a Mo...
From Zero to Iterators: Building and Extending the Iterator Hierarchy in a Mo...From Zero to Iterators: Building and Extending the Iterator Hierarchy in a Mo...
From Zero to Iterators: Building and Extending the Iterator Hierarchy in a Mo...
 
Achieving Parsing Sanity In Erlang
Achieving Parsing Sanity In ErlangAchieving Parsing Sanity In Erlang
Achieving Parsing Sanity In Erlang
 
Perl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim PerlchinaPerl.Hacks.On.Vim Perlchina
Perl.Hacks.On.Vim Perlchina
 
Perl Xpath Lightning Talk
Perl Xpath Lightning TalkPerl Xpath Lightning Talk
Perl Xpath Lightning Talk
 
Maybe you do not know that ...
Maybe you do not know that ...Maybe you do not know that ...
Maybe you do not know that ...
 
ScotRuby - Dark side of ruby
ScotRuby - Dark side of rubyScotRuby - Dark side of ruby
ScotRuby - Dark side of ruby
 
Using DAOs without implementing them
Using DAOs without implementing themUsing DAOs without implementing them
Using DAOs without implementing them
 
Cs hangman
Cs   hangmanCs   hangman
Cs hangman
 
Round PEG, Round Hole - Parsing Functionally
Round PEG, Round Hole - Parsing FunctionallyRound PEG, Round Hole - Parsing Functionally
Round PEG, Round Hole - Parsing Functionally
 
Working with text, Regular expressions
Working with text, Regular expressionsWorking with text, Regular expressions
Working with text, Regular expressions
 
Zen and the Art of Code Maintenance
Zen and the Art of Code MaintenanceZen and the Art of Code Maintenance
Zen and the Art of Code Maintenance
 
The Perl API for the Mortally Terrified (beta)
The Perl API for the Mortally Terrified (beta)The Perl API for the Mortally Terrified (beta)
The Perl API for the Mortally Terrified (beta)
 
Beautiful PHP CLI Scripts
Beautiful PHP CLI ScriptsBeautiful PHP CLI Scripts
Beautiful PHP CLI Scripts
 
Python Workshop
Python  Workshop Python  Workshop
Python Workshop
 
Make Your Own Perl with Moops
Make Your Own Perl with MoopsMake Your Own Perl with Moops
Make Your Own Perl with Moops
 
Erlang/OTP for Rubyists
Erlang/OTP for RubyistsErlang/OTP for Rubyists
Erlang/OTP for Rubyists
 
Rails for PHP Developers
Rails for PHP DevelopersRails for PHP Developers
Rails for PHP Developers
 
Python idiomatico
Python idiomaticoPython idiomatico
Python idiomatico
 
Ruby Topic Maps Tutorial (2007-10-10)
Ruby Topic Maps Tutorial (2007-10-10)Ruby Topic Maps Tutorial (2007-10-10)
Ruby Topic Maps Tutorial (2007-10-10)
 

Ähnlich wie Php 2

What Is Php
What Is PhpWhat Is Php
What Is PhpAVC
 
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 Training
Php TrainingPhp Training
Php Trainingadfa
 
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 Loop
Php LoopPhp Loop
Php Looplotlot
 
Python - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave ParkPython - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave Parkpointstechgeeks
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Coursemussawir20
 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQLOpen Source Package PHP & MySQL
Open Source Package PHP & MySQLkalaisai
 
Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9isadorta
 
Introduction to Perl - Day 1
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1Dave Cross
 
What's new in Perl 5.10?
What's new in Perl 5.10?What's new in Perl 5.10?
What's new in Perl 5.10?acme
 
Writing Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniterWriting Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniterCodeIgniter Conference
 

Ähnlich wie Php 2 (20)

What Is Php
What Is PhpWhat Is Php
What Is Php
 
SPL, not a bridge too far
SPL, not a bridge too farSPL, not a bridge too far
SPL, not a bridge too far
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
 
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 Training
Php TrainingPhp Training
Php Training
 
02 Php Vars Op Control Etc
02 Php Vars Op Control Etc02 Php Vars Op Control Etc
02 Php Vars Op Control Etc
 
PHP MySQL
PHP MySQLPHP MySQL
PHP MySQL
 
Control Structures In Php 2
Control Structures In Php 2Control Structures In Php 2
Control Structures In Php 2
 
Modern Perl
Modern PerlModern Perl
Modern Perl
 
Php Loop
Php LoopPhp Loop
Php Loop
 
Python - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave ParkPython - Getting to the Essence - Points.com - Dave Park
Python - Getting to the Essence - Points.com - Dave Park
 
C to perl binding
C to perl bindingC to perl binding
C to perl binding
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Course
 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQLOpen Source Package PHP & MySQL
Open Source Package PHP & MySQL
 
Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9
 
Introduction to Perl - Day 1
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1
 
Jquery 1
Jquery 1Jquery 1
Jquery 1
 
Basic PHP
Basic PHPBasic PHP
Basic PHP
 
What's new in Perl 5.10?
What's new in Perl 5.10?What's new in Perl 5.10?
What's new in Perl 5.10?
 
Writing Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniterWriting Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniter
 

Kürzlich hochgeladen

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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
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
 
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
 
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.pdfhans926745
 
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 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
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 Scriptwesley chun
 
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 Takeoffsammart93
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 

Kürzlich hochgeladen (20)

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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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 🐘
 
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
 
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
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
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...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 

Php 2

  • 1.
  • 2. if...else statement - use this statement to execute some code if a condition is true and another code if the condition is false
  • 3. if...elseif....else statement - use this statement to select one of several blocks of code to be executed
  • 4.
  • 5. The if...else Statement <?php$d=date("D");if ($d=="Fri")  echo "Have a nice weekend!";else  echo "Have a nice day!";?>
  • 6. The if...elseif....else Statement <?php $d=date("D"); if ($d=="Fri")  echo "Have a nice weekend!"; elseif ($d=="Sun")  echo "Have a nice Sunday!"; else  echo "Have a nice day!"; ?>
  • 7. Switch Statement <?phpswitch ($x){case 1:  echo "Number 1";  break;case 2:  echo "Number 2";  break;case 3:  echo "Number 3";  break;default:  echo "No number between 1 and 3";}?>
  • 8.
  • 9. Associative array - An array where each ID key is associated with a value
  • 10.
  • 11. Associative Arrays An associative array, each ID key is associated with a value. $ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34); $ages['Peter'] = "32";$ages['Quagmire'] = "30";$ages['Joe'] = "34";
  • 12. <?php$ages['Peter'] = "32";$ages['Quagmire'] = "30";$ages['Joe'] = "34";echo "Peter is " . $ages['Peter'] . " years old."; ?>
  • 13. Multidimensional Arrays In a multidimensional array, each element in the main array can also be an array. And each element in the sub-array can be an array, and so on. $families = array  (  "Griffin"=>array  (  "Peter",  "Lois",  "Megan"  ),  "Quagmire"=>array  (  "Glenn"  ),  "Brown"=>array  (  "Cleveland",  "Loretta",  "Junior"  )  );
  • 14. Array([Griffin] => Array  (  [0] => Peter  [1] => Lois  [2] => Megan  )[Quagmire] => Array  (  [0] => Glenn  )[Brown] => Array  (  [0] => Cleveland  [1] => Loretta  [2] => Junior  ))
  • 15.
  • 16. do...while - loops through a block of code once, and then repeats the loop as long as a specified condition is true
  • 17. for - loops through a block of code a specified number of times
  • 18.
  • 19. The do...while Statement The do...while statement will always execute the block of code once, it will then check the condition, and repeat the loop while the condition is true. <?php$i=1;do  {  $i++;  echo "The number is " . $i . "<br />";  }while ($i<=5);?>
  • 20. The for Loop The for loop is used when you know in advance how many times the script should run. <?phpfor ($i=1; $i<=5; $i++)  {  echo "The number is " . $i . "<br />";  }?>
  • 21. The foreach Loop The foreach loop is used to loop through arrays. <?php$x=array("one","two","three");foreach ($x as $value)  {  echo $value . "<br />";  }?>
  • 22. Functions A function will be executed by a call to the function. <?phpfunction writeName(){echo "Kai Jim Refsnes";}echo "My name is ";writeName();?>
  • 23. Functions - Adding parameters Parameters are specified after the function name, inside the parentheses. <?phpfunction writeName($fname){echo $fname . " Abraham.<br />";}echo "My name is ";writeName("Kai Jim");echo "My sister's name is ";writeName("Hege");echo "My brother's name is ";writeName("Stale");?>
  • 24. Functions - Return values <?phpfunction add($x,$y){$total=$x+$y;return $total;} echo "1 + 16 = " . add(1,16); ?>
  • 25. Using the break Statement 1: <?php 2: $counter = -4; 3: for (; $counter <= 10; $counter++) { 4: if ($counter == 0) { 5: break; 6: } else { 7: $temp = 4000/$counter; 8: echo “4000 divided by $counter is... $temp<br>”; 9: } 10: } 11 ?> By The Way Dividing a number by zero does not cause a fatal error in PHP. Instead, PHP generates a warning and execution continues. Did You Know? You can omit any of the expressions from a for statement, but you must remember to retain the separation semicolons.
  • 26. Ouput 4000 divided by -4 is... -1000 4000 divided by -3 is... -1333.33333333 4000 divided by -2 is... -2000 4000 divided by -1 is... -4000
  • 27. Using the continue Statement 1: <?php 2: $counter = -4; 3: for (; $counter <= 10; $counter++) { 4: if ($counter == 0) { 5: continue; 6: } 7: $temp = 4000/$counter; 8: echo “4000 divided by $counter is... $temp<br>”; 9: } 10:?> Watch Out! Using the break and continue statements can make code more difficult to read, because they often add layers of complexity to the logic of the loop statements that contain them. Use these statements with care, or comment your code to show other programmers (or yourself) just what you’re trying to achieve with these statements.
  • 28. Output 4000 divided by -4 is... -1000 4000 divided by -3 is... -1333.33333333 4000 divided by -2 is... -2000 4000 divided by -1 is... -4000 4000 divided by 1 is... 4000 4000 divided by 2 is... 2000 4000 divided by 3 is... 1333.33333333 4000 divided by 4 is... 1000 4000 divided by 5 is... 800 4000 divided by 6 is... 666.666666667 4000 divided by 7 is... 571.428571429 4000 divided by 8 is... 500 4000 divided by 9 is... 444.444444444
  • 29. Nested Looping 1: <?php 2: echo “<table border=1 cellpadding=4 cellspacing=4>”; 3: for ($y=1; $y<=12; $y++) { 4: echo “<tr> ”; 5: for ($x=1; $x<=12; $x++) { 6: echo “<td>”; 7: echo ($x * $y); 8: echo “</td> ”; 9:} 10:echo “</tr> ”; 11: } 12: echo “</table>”; 13: ?>
  • 30. Cell Spacing & Cell Padding CELLPADDING and CELLSPACING By default, table cells tend to be squeezed close to each other. To give your table cells a little more breathing room, useCELLPADDING and CELLSPACING. CELLSPACING controls the space between table cells. Although there is no official default, browsers usually use a default of 2.  <TABLE BORDER> <TABLE BORDER CELLSPACING=2> <TABLE BORDER CELLSPACING=10> peachescherrieswalnutsalmondspeachescherrieswalnutsalmondspeachescherrieswalnutsalmondsCELLPADDING sets the amount of space between the contents of the cell and the cell wall. The default is 1. CELLPADDING is usually more effective thanCELLSPACING for spreading out the contents of the table.  <TABLE BORDER> <TABLE BORDER CELLPADDING=1> <TABLE BORDER CELLPADDING=10> peachescherrieswalnutsalmondspeachescherrieswalnutsalmondspeachescherrieswalnutsalmonds