SlideShare a Scribd company logo
Day 2  PHP  Geshan Manandhar Developer,  Young Innovations Pvt. Limited www.geshanmanandhar.com http://www.php.net
Variables in PHP Boolean: It can be either  TRUE  or  FALSE .  Integer: The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value. Float: The size of a float is platform-dependent, although a maximum of ~1.8e308 with a precision of roughly 14 decimal digits is a common value
Variable in PHP String: A string is series of characters. In PHP, a character is the same as a byte, that is, there are exactly 256 different characters possible.  Array: An array in PHP is actually an ordered map. A map is a type that maps  values  to  keys .  $names[1] = “Ram”; $names[2] = “Shyam”;
Variables in PHP Objects: mainly have attributes and functions. <?php class test { function do_test() { echo &quot;Testing class function.&quot;;  } } $an_object = new test; $an_object->do_test(); ?>
Naming variables in PHP Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive.  A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.  $a_5=10; //valid $#b = 20; //invalid Predefined Variables ($_SERVER, $_POST)
Constant You can define a constant by using the define() -function. Once a constant is defined, it can never be changed or undefined.  <?php define(&quot;PI&quot;, 3.1415); //defining a constant called PI $r=5; //r for radius $area = PI*$r*$r; //area calculation of circle print &quot;Areas of circle with radius $r is &quot;.$area.&quot;.&quot;; //user number_format() yourself. ?>
Arithmetic Operators See Program for more clarification: Day02\prog06_Operators.php
Comparison Operators See code of Day02\prog08_comparision_operators.php
Increment Decrement Operators ++ and -- Code at Day02\prog09_inc_dec_operator.php
Logical Operator
String Operator .  used to concatenate strings .= used to append a string. <?php $b = ”Hello” . &quot;World!&quot;; // now $b contains &quot;Hello World!&quot; $a = &quot;Hello &quot;; $a .= &quot;World!&quot;;  // now $a contains &quot;Hello World!&quot; ?>
If-else if- else <?php $a=10; $b=17; if ($a > $b) { echo &quot;a is bigger than b&quot;; } elseif ($a == $b) { echo &quot;a is equal to b&quot;; } else { echo &quot;a is smaller than b&quot;; } ?>
If-else if- else alternate <?php $a=10; $b=17; if ($a > $b) : echo &quot;a is bigger than b&quot;; elseif ($a == $b) : echo &quot;a is equal to b&quot;; else : echo &quot;a is smaller than b&quot;; endif; ?>
Switch Example <?php $engDay =date (&quot;l&quot;); switch ($engDay) { case &quot;Friday&quot;; print &quot;Thank god its Friday&quot;; break; case &quot;Saturday&quot;; print &quot;Oh its week end Saturday&quot;; break; default:  print &quot;Its just another working day of the week.&quot;; } ?>
While Loop <?php $i = 1; while ($i <= 10) { echo $i++;  } /* example 2 Alternative syntax*/ $i = 1; while  ($i <= 10): echo $i; $i++; endwhile; ?>
Do While Loop <?php $i = 0; do {     echo $i; } while ($i > 0); ?>
For Loop <?php for ($i = 1; $i <= 10; $i++) { echo $i; } /*Alternate for Syntax */ for($i = 0; $i <= 10; $i++): echo &quot;--&quot;.$i; endfor; ?>
For Each loop <?php $arr = array(&quot;zero&quot; , &quot;one&quot; , &quot;two&quot; , &quot;three&quot; , &quot;four&quot; ); /*For each example 1 */ foreach ( $arr as $value ){ print &quot;<br>&quot;.$value; } print &quot;<br>&quot;; /*For each example 2 */ foreach ( $arr as $key => $value) { print &quot;<br>At key &quot;.$key.&quot; of the array, the value is &quot;.$value; } ?>
PHP simple Function <?php function adder($var1, $var2){ $sum = $var1+$var2; return $sum; } ?>  <html> <head> <title>Function with PHP an example</title> </head> <body> <?php $a=10; $b=15; $added = adder($a, $b); ?> The sum of <?=$a?> and <?=$b?>  is <?=$added?>. </body> </html>
Lets get rolling Write a program that performs all arithmetic operations with 3 variables. Get the month with date(“F”) function and if its December and day date(“d”) is greater than 20 and less than 26, print “Merry Christmas”.  Print multiplication table of 5 with for loop. Use foreach loop for an array called names and print the names in the array with its keys.
Questions are welcome That’s why god gave us two eyes, two ears but only one mouth.

More Related Content

What's hot (20)

ODP
PHP Tips for certification - OdW13
julien pauli
 
ODP
The promise of asynchronous PHP
Wim Godden
 
PPT
PHP - Introduction to PHP - Mazenet Solution
Mazenetsolution
 
PDF
PHP7. Game Changer.
Haim Michael
 
PPT
PHP variables
Siddique Ibrahim
 
PDF
Data Types In PHP
Mark Niebergall
 
PPT
Class 3 - PHP Functions
Ahmed Swilam
 
PDF
Functions in PHP
Vineet Kumar Saini
 
PPT
Class 2 - Introduction to PHP
Ahmed Swilam
 
KEY
Intermediate PHP
Bradley Holt
 
PPTX
PHP Basics
Henry Osborne
 
PPT
Introduction To Php For Wit2009
cwarren
 
PDF
PHP Enums - PHPCon Japan 2021
Ayesh Karunaratne
 
PDF
Linux shell script-1
兎 伊藤
 
PPT
Php my sql - functions - arrays - tutorial - programmerblog.net
Programmer Blog
 
PDF
PHP 7.0 new features (and new interpreter)
Andrea Telatin
 
PPT
Introduction to web and php mysql
Programmer Blog
 
PDF
2014 database - course 2 - php
Hung-yu Lin
 
PPT
Download It
webhostingguy
 
PHP Tips for certification - OdW13
julien pauli
 
The promise of asynchronous PHP
Wim Godden
 
PHP - Introduction to PHP - Mazenet Solution
Mazenetsolution
 
PHP7. Game Changer.
Haim Michael
 
PHP variables
Siddique Ibrahim
 
Data Types In PHP
Mark Niebergall
 
Class 3 - PHP Functions
Ahmed Swilam
 
Functions in PHP
Vineet Kumar Saini
 
Class 2 - Introduction to PHP
Ahmed Swilam
 
Intermediate PHP
Bradley Holt
 
PHP Basics
Henry Osborne
 
Introduction To Php For Wit2009
cwarren
 
PHP Enums - PHPCon Japan 2021
Ayesh Karunaratne
 
Linux shell script-1
兎 伊藤
 
Php my sql - functions - arrays - tutorial - programmerblog.net
Programmer Blog
 
PHP 7.0 new features (and new interpreter)
Andrea Telatin
 
Introduction to web and php mysql
Programmer Blog
 
2014 database - course 2 - php
Hung-yu Lin
 
Download It
webhostingguy
 

Similar to 02 Php Vars Op Control Etc (20)

PPT
Php Crash Course
mussawir20
 
PPTX
John Rowley Notes
IBAT College
 
PPT
What Is Php
AVC
 
PPT
Introduction To Lamp
Amzad Hossain
 
PPT
Open Source Package PHP & MySQL
kalaisai
 
PPT
Open Source Package Php Mysql 1228203701094763 9
isadorta
 
PPT
Control Structures In Php 2
Digital Insights - Digital Marketing Agency
 
PPT
PHP MySQL
Md. Sirajus Salayhin
 
PPT
course slides -- powerpoint
webhostingguy
 
PPT
Php Calling Operators
mussawir20
 
PPT
Php Training
adfa
 
PPT
Internet Technology and its Applications
amichoksi
 
PPTX
Php Loop
lotlot
 
PPT
Basic PHP
Todd Barber
 
PPT
P H P Part I, By Kian
phelios
 
PPT
Php Reusing Code And Writing Functions
mussawir20
 
PPT
Web development
Seerat Bakhtawar
 
PPT
Dynamic Web Pages Ch 1 V1.0
Cathie101
 
Php Crash Course
mussawir20
 
John Rowley Notes
IBAT College
 
What Is Php
AVC
 
Introduction To Lamp
Amzad Hossain
 
Open Source Package PHP & MySQL
kalaisai
 
Open Source Package Php Mysql 1228203701094763 9
isadorta
 
Control Structures In Php 2
Digital Insights - Digital Marketing Agency
 
course slides -- powerpoint
webhostingguy
 
Php Calling Operators
mussawir20
 
Php Training
adfa
 
Internet Technology and its Applications
amichoksi
 
Php Loop
lotlot
 
Basic PHP
Todd Barber
 
P H P Part I, By Kian
phelios
 
Php Reusing Code And Writing Functions
mussawir20
 
Web development
Seerat Bakhtawar
 
Dynamic Web Pages Ch 1 V1.0
Cathie101
 
Ad

More from Geshan Manandhar (20)

PDF
How to build an image to geo location guesser using Gemini 2 - Canberra.pdf
Geshan Manandhar
 
PDF
build-with-ai-sydney AI for web devs Tamas Piros
Geshan Manandhar
 
PDF
Are logs a software engineer’s best friend? Yes -- follow these best practices
Geshan Manandhar
 
PDF
We lost $ 20.5K in one day and how we could have saved it… hint: better autom...
Geshan Manandhar
 
PDF
Moving from A and B to 150 microservices, the journey, and learnings
Geshan Manandhar
 
PDF
Adopt a painless continuous delivery culture, add more business value
Geshan Manandhar
 
PDF
Things i wished i knew as a junior developer
Geshan Manandhar
 
PDF
Embrace chatops, stop installing deployment software - Laracon EU 2016
Geshan Manandhar
 
PDF
Do You Git Your Code? Follow Simplified Gitflow Branching Model to Improve Pr...
Geshan Manandhar
 
PDF
Embrace chatOps, stop installing deployment software
Geshan Manandhar
 
PDF
7 rules of simple and maintainable code
Geshan Manandhar
 
PDF
Software engineering In Nepal mid 2015 part 01
Geshan Manandhar
 
PDF
A simplified Gitflow
Geshan Manandhar
 
PDF
How to become a better software company technically
Geshan Manandhar
 
PDF
Things I wished I knew while doing my tech bachelor / undergraduate
Geshan Manandhar
 
PDF
Message Queues a basic overview
Geshan Manandhar
 
PDF
Most popular brands, people on facebook in nepal as of 2013 q4
Geshan Manandhar
 
PDF
Drupal 7 basic setup and contrib modules for a brochure website
Geshan Manandhar
 
PPTX
Git intro hands on windows with msysgit
Geshan Manandhar
 
ODP
Drupal 7 install with modules and themes
Geshan Manandhar
 
How to build an image to geo location guesser using Gemini 2 - Canberra.pdf
Geshan Manandhar
 
build-with-ai-sydney AI for web devs Tamas Piros
Geshan Manandhar
 
Are logs a software engineer’s best friend? Yes -- follow these best practices
Geshan Manandhar
 
We lost $ 20.5K in one day and how we could have saved it… hint: better autom...
Geshan Manandhar
 
Moving from A and B to 150 microservices, the journey, and learnings
Geshan Manandhar
 
Adopt a painless continuous delivery culture, add more business value
Geshan Manandhar
 
Things i wished i knew as a junior developer
Geshan Manandhar
 
Embrace chatops, stop installing deployment software - Laracon EU 2016
Geshan Manandhar
 
Do You Git Your Code? Follow Simplified Gitflow Branching Model to Improve Pr...
Geshan Manandhar
 
Embrace chatOps, stop installing deployment software
Geshan Manandhar
 
7 rules of simple and maintainable code
Geshan Manandhar
 
Software engineering In Nepal mid 2015 part 01
Geshan Manandhar
 
A simplified Gitflow
Geshan Manandhar
 
How to become a better software company technically
Geshan Manandhar
 
Things I wished I knew while doing my tech bachelor / undergraduate
Geshan Manandhar
 
Message Queues a basic overview
Geshan Manandhar
 
Most popular brands, people on facebook in nepal as of 2013 q4
Geshan Manandhar
 
Drupal 7 basic setup and contrib modules for a brochure website
Geshan Manandhar
 
Git intro hands on windows with msysgit
Geshan Manandhar
 
Drupal 7 install with modules and themes
Geshan Manandhar
 
Ad

Recently uploaded (20)

PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
July Patch Tuesday
Ivanti
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Python basic programing language for automation
DanialHabibi2
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 

02 Php Vars Op Control Etc

  • 1. Day 2 PHP Geshan Manandhar Developer, Young Innovations Pvt. Limited www.geshanmanandhar.com http://www.php.net
  • 2. Variables in PHP Boolean: It can be either TRUE or FALSE . Integer: The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value. Float: The size of a float is platform-dependent, although a maximum of ~1.8e308 with a precision of roughly 14 decimal digits is a common value
  • 3. Variable in PHP String: A string is series of characters. In PHP, a character is the same as a byte, that is, there are exactly 256 different characters possible. Array: An array in PHP is actually an ordered map. A map is a type that maps values to keys . $names[1] = “Ram”; $names[2] = “Shyam”;
  • 4. Variables in PHP Objects: mainly have attributes and functions. <?php class test { function do_test() { echo &quot;Testing class function.&quot;; } } $an_object = new test; $an_object->do_test(); ?>
  • 5. Naming variables in PHP Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. $a_5=10; //valid $#b = 20; //invalid Predefined Variables ($_SERVER, $_POST)
  • 6. Constant You can define a constant by using the define() -function. Once a constant is defined, it can never be changed or undefined. <?php define(&quot;PI&quot;, 3.1415); //defining a constant called PI $r=5; //r for radius $area = PI*$r*$r; //area calculation of circle print &quot;Areas of circle with radius $r is &quot;.$area.&quot;.&quot;; //user number_format() yourself. ?>
  • 7. Arithmetic Operators See Program for more clarification: Day02\prog06_Operators.php
  • 8. Comparison Operators See code of Day02\prog08_comparision_operators.php
  • 9. Increment Decrement Operators ++ and -- Code at Day02\prog09_inc_dec_operator.php
  • 11. String Operator . used to concatenate strings .= used to append a string. <?php $b = ”Hello” . &quot;World!&quot;; // now $b contains &quot;Hello World!&quot; $a = &quot;Hello &quot;; $a .= &quot;World!&quot;;  // now $a contains &quot;Hello World!&quot; ?>
  • 12. If-else if- else <?php $a=10; $b=17; if ($a > $b) { echo &quot;a is bigger than b&quot;; } elseif ($a == $b) { echo &quot;a is equal to b&quot;; } else { echo &quot;a is smaller than b&quot;; } ?>
  • 13. If-else if- else alternate <?php $a=10; $b=17; if ($a > $b) : echo &quot;a is bigger than b&quot;; elseif ($a == $b) : echo &quot;a is equal to b&quot;; else : echo &quot;a is smaller than b&quot;; endif; ?>
  • 14. Switch Example <?php $engDay =date (&quot;l&quot;); switch ($engDay) { case &quot;Friday&quot;; print &quot;Thank god its Friday&quot;; break; case &quot;Saturday&quot;; print &quot;Oh its week end Saturday&quot;; break; default: print &quot;Its just another working day of the week.&quot;; } ?>
  • 15. While Loop <?php $i = 1; while ($i <= 10) { echo $i++; } /* example 2 Alternative syntax*/ $i = 1; while ($i <= 10): echo $i; $i++; endwhile; ?>
  • 16. Do While Loop <?php $i = 0; do {     echo $i; } while ($i > 0); ?>
  • 17. For Loop <?php for ($i = 1; $i <= 10; $i++) { echo $i; } /*Alternate for Syntax */ for($i = 0; $i <= 10; $i++): echo &quot;--&quot;.$i; endfor; ?>
  • 18. For Each loop <?php $arr = array(&quot;zero&quot; , &quot;one&quot; , &quot;two&quot; , &quot;three&quot; , &quot;four&quot; ); /*For each example 1 */ foreach ( $arr as $value ){ print &quot;<br>&quot;.$value; } print &quot;<br>&quot;; /*For each example 2 */ foreach ( $arr as $key => $value) { print &quot;<br>At key &quot;.$key.&quot; of the array, the value is &quot;.$value; } ?>
  • 19. PHP simple Function <?php function adder($var1, $var2){ $sum = $var1+$var2; return $sum; } ?> <html> <head> <title>Function with PHP an example</title> </head> <body> <?php $a=10; $b=15; $added = adder($a, $b); ?> The sum of <?=$a?> and <?=$b?> is <?=$added?>. </body> </html>
  • 20. Lets get rolling Write a program that performs all arithmetic operations with 3 variables. Get the month with date(“F”) function and if its December and day date(“d”) is greater than 20 and less than 26, print “Merry Christmas”. Print multiplication table of 5 with for loop. Use foreach loop for an array called names and print the names in the array with its keys.
  • 21. Questions are welcome That’s why god gave us two eyes, two ears but only one mouth.

Editor's Notes

  • #5: Assign $global and $GLOBALS