SlideShare a Scribd company logo
PHP Basic
Khem Puthea
putheakhemdeveloper@gmail.com
Part I: Understanding PHP Basics
Using Variables and Operators
Prepared by KhmerCourse
Storing Data in Variables
៚ Some simple rules for naming variables
៙ Be preceded with a dollar symbol $
៙ And begin with a letter or underscore _
៙ Optionally followed by more letters, numbers, or underscore
៙ Be not permitted
ៜ Punctuation: commas ,, quotation marks ?, or periods .
ៜ Spaces
៙ e.g.
ៜ $id, $_name and $query3: valid
ៜ $96, $day. and email: invalid
៚ Variable names are case-sensitive.
៙ e.g. $name and $Name refer to different variables.
3
Assigning Values to Variables
៚ $var = val;
៙ e.g. assigningValues2Variables.php
<?php $language = "PHP"; ?>
<h1>Welcome <?php echo $language; ?></h1>
៚ Dynamic variable's name
៙ e.g. dynamicVariableName.php
<?php
$clone = "real";
// create a
value of
${$clone} =
echo $real;
?>
new variable dynamically
$clone
"REAL";
// output: REAL
at run time from the
Is it possible for a variable's name itself to be a variable?
៚ echo(): print the value of a variable
4
Destroying Variables
៚ e.g. destroyingVariables.php
<?php
$apple = "Apple";
echo $apple; // output: Apple
// unset()
unset($apple);
echo $apple; // error: Undefined variable
$banana = "Banana";
echo $banana; //
// NULL value
$banana = NULL;
echo $banana; //
?>
output: Banana
output: (nothing)
5
Inspecting Variable Contents
៚ e.g. inspectingVariableContents.php
<?php
$apple = "Apple"; $yr = 2011;
// var_dump()
var_dump($apple);
var_dump($yr); //
// output: string(5)
output: int(2011)
"Apple"
// print_r()
print_r($apple); // output: Apple
print_r($yr);
?>
// output: 2011
6
Understanding PHP’s Data Types
៚ Data type is the values assigned to a variable.
៚ Booleans
៙ 1 (true) or 0 (false)
៚ 2 numeric
៙ Floating-point values (a.k.a floats or doubles) are decimal or fractional
numbers,
៙ While integers are round numbers.
៚ Non-numeric: String
៙ Be enclosed in single quotes (') or double quotes (")
៚ NULL (a special data type in PHP4)
៙ Represent empty variables; a variable of type NULL is a variable without
any data.
A NULL value is not equivalent to an empty string "".
7
Understanding PHP’s Data Types (cont.)
៚ e.g. hexadecimal_octal_scientificNotation.php
<?php
$dec
echo
= 8; // decimal
$dec; // output: 8
$oct
echo
= 010; // octal
$oct; // output: 8
$hex
echo
= 0x5dc;
$hex; //
// hexadecimal
output: 1500
// scientific notation
$sn1
$sn2
echo
?>
= 6.9e+2;
= 6.9e-2;
$sn1." ".$sn2; // output: 690 0.069
8
Setting and Checking Variable Data Types
៚ e.g. setting_CheckingVariableDataTypes.php
<?php
$apple = "Apple";
echo gettype($apple); // output: string
$yr = 2011;
echo gettype($yr); // output: integer
$valid = true;
echo gettype($valid); // output : boolean
echo gettype($banana); // output: NULL
variable)
(error: Undefined
$empty = NULL;
echo gettype($empty); // output: NULL
?>
9
Setting and Checking Variable Data Types (cont.)
៚ e.g. casting.php
<?php
$f_speed =
$i_speed =
// output:
36.9; // floating-point
(integer)
36.9
$f_speed; // cast to integer
echo $f_speed;
// output: 36
echo
?>
$i_speed;;
10
Data Type Checking Functions
Function Purpose
is_bool Test if holding a Boolean value
is_numeric Test if holding a numeric value
is_int Test if holding an integer value
is_float Test if holding a float value
is_string Test if holding a string value
is_null Test if holding a NULL value
is_array Test if being an array
is_object Test if being an object
Using Constants
៚ define(CONST, val);
៚ Constant names follows the same rules as variable names but not the $
៚ e.g. usingConstants.php
<?php
define("APPLE", "Apple");
define("YR", 2011);
prefix.
// output: Apple 2011
echo
?>
APPLE." ".YR;
Constants name are usually entirely UPPERCASED.
When should we use a variable, and when should we use a constant?
11
Manipulating Variables with Operators
៚ Operators are symbols that tell the PHP processor to perform certain actions.
៚ PHP supports more than 50 such operators, ranging from operators for
arithmetical operations to operators for logical comparison and bitwise
calculations.
12
Performing Arithmetic Operations
៚ e.g. arithmeticOperations.php
<?php
echo 3 + 2; // output: 5
echo 3 - 2; // output: 1
echo 3 * 2; // output: 6
echo 3 / 2; // output: 1.5
echo
?>
3 % 2; // output: 1
Is there any limit on how large a PHP integer value can be?
13
Arithmetic Operators
Operator Description
+ Add
- Subtract
* Multiply
/ Divide
% Modulus
Concatenating Strings
៚ e.g. concatenatingStrings.php
<?php
$apple = "Apple";
$banana = "Banana";
// use (.) to join strings into 1
$fruits = $apple." and ".$banana;
// output: I love apple and
".$fruits.".";
banana..
echo
?>
"I love
14
Comparing Variables
៚ e.g. comparingVariables.php
<?php
$num = 6; $num2 = 3; $str = "6";
// output:
echo ($num
// output:
echo ($num
0
<
1
>
(false)
$num2);
(true)
$num2);
// output:
echo ($num
0
<
(false)
$str);
// output:
echo ($num
// output:
echo ($num
?>
1 (true)
== $str);
0 (false)
=== $str);
15
Comparison Operators
Operator Description
== Equal to
!= Not equal to
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to
=== Equal to and of the same type
Performing Logical Tests
៚ e.g. performingLogicalTests.php
<?php
// output:
echo (true
// output:
echo (true
// output:
1 (true)
&& true);
0 (false)
&& false);
0 (false)
echo (false && false);
// output: 1 (true)
echo (false || true);
// output: 0 (false)
echo (!true);
?>
16
Logical Operators
Operator Description
&& AND
|| OR
! NOT
Other Useful Operators
៚ e.g. otherUsefulOperators.php
<?php
$count = 7; $age = 60; $greet = "We";
Increased by 1: ++
Decreased by 1: --
$count -= 2;
// output: 5
echo $count;
e.g. $count++; // $count = $count + 1;
$age /= 5;
// output: 12
echo $age;
$greet .= "lcome!";
// output: Welcome!
echo $greet;
?>
17
Assignment Operators
Operator Description
+= Add, assign
-= Subtract, assign
*= Multiply, assign
/= Divide, assign
%= Modulus, assign
.= Concatenate, assign
Understanding Operator Precedence
៚ Operators at the same level have equal precedence:
៙ ++
៙ !
៙ *
៙ +
៙ <
៙ ==
៙ &&
៙ ||
៙ =
--
/
-
<=
!=
%
.
> >=
=== !==
+= -= *= /= .= %= &= |= ^=
៚ Parentheses (
៚ e.g.
៙ 3 + 2 *
៙ (3 + 2)
): force PHP to evaluate it first
5; // 3 + 10 = 13
* 5; // 5 * 5 = 25
18
Handling Form Input
៚ e.g. chooseCar.html
<form name="fCar" method="POST" action="getCar.php">
<select name="selType">
<option value="Porsche">Porsche</option>
<option value="Ford">Ford</option>
</select>
Color:
<input
<input
</form>
type="text" name="txtColor" />
type="submit" value="get Car" />
action="getCar.php"
Reference a PHP script
method="POST"
Submission via POST
GET: method="GET"
19
Handling Form Input (cont.)
៚ e.g. getCar.php
<?php
// get values via $_POST | $_GET
$type = $_POST["selType"];
$color = $_POST["txtColor"];
echo $color." ".$type;
?>
$_POST[fieldName];
$_POST: a special container variable (array) is used to get a value of a field
of a form sent by using the POST method (or $_GET for the GET method).
fieldName: the field whose value will be get/assigned to a variable.
20
The End
21
The End

More Related Content

What's hot (20)

Learning HTML
Learning HTMLLearning HTML
Learning HTML
Md. Sirajus Salayhin
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
WordPress Memphis
 
Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2
MOHIT TOMAR
 
HTML (Web) basics for a beginner
HTML (Web) basics for a beginnerHTML (Web) basics for a beginner
HTML (Web) basics for a beginner
Jayapal Reddy Nimmakayala
 
Lesson 2 php data types
Lesson 2   php data typesLesson 2   php data types
Lesson 2 php data types
MLG College of Learning, Inc
 
Files and streams
Files and streamsFiles and streams
Files and streams
Pranali Chaudhari
 
Presentation on function
Presentation on functionPresentation on function
Presentation on function
Abu Zaman
 
C Programming : Pointers and Strings
C Programming : Pointers and StringsC Programming : Pointers and Strings
C Programming : Pointers and Strings
Selvaraj Seerangan
 
CSS
CSS CSS
CSS
Sunil OS
 
PHP
PHPPHP
PHP
Steve Fort
 
Bootstrap PPT by Mukesh
Bootstrap PPT by MukeshBootstrap PPT by Mukesh
Bootstrap PPT by Mukesh
Mukesh Kumar
 
Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
Tiji Thomas
 
Types of Selectors (HTML)
Types of Selectors (HTML)Types of Selectors (HTML)
Types of Selectors (HTML)
Deanne Alcalde
 
Operators php
Operators phpOperators php
Operators php
Chandni Pm
 
Database Connectivity in PHP
Database Connectivity in PHPDatabase Connectivity in PHP
Database Connectivity in PHP
Taha Malampatti
 
Cascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) helpCascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) help
casestudyhelp
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
shanmukhareddy dasi
 
Php
PhpPhp
Php
Ajaigururaj R
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
Nidhi mishra
 
Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1
Gheyath M. Othman
 

Viewers also liked (20)

Sign up github
Sign up githubSign up github
Sign up github
Khem Puthea
 
Introduction to css part1
Introduction to css part1Introduction to css part1
Introduction to css part1
Khem Puthea
 
Membuat partisi di os windows
Membuat partisi di os windowsMembuat partisi di os windows
Membuat partisi di os windows
Nugroho Setiawan
 
Facebook Tackle Box: 10 Apps & Tools Every Brand Should Use
Facebook Tackle Box: 10 Apps & Tools Every Brand Should UseFacebook Tackle Box: 10 Apps & Tools Every Brand Should Use
Facebook Tackle Box: 10 Apps & Tools Every Brand Should Use
Firebelly Marketing
 
Q2 2013 ASSA ABLOY investors presentation 19 july
Q2 2013 ASSA ABLOY investors presentation 19 julyQ2 2013 ASSA ABLOY investors presentation 19 july
Q2 2013 ASSA ABLOY investors presentation 19 july
ASSA ABLOY
 
C53200
C53200C53200
C53200
Subhraneel Dey
 
srgoc
srgocsrgoc
srgoc
Gaurav Singh
 
Numeración romana
Numeración romanaNumeración romana
Numeración romana
Samuel Rodríguez
 
Time Management within IT Project Management
Time Management within IT Project ManagementTime Management within IT Project Management
Time Management within IT Project Management
rielaantonio
 
Granada425
Granada425Granada425
Granada425
sjacaruso
 
Caring for Sharring
 Caring for Sharring  Caring for Sharring
Caring for Sharring
faleulaaoelua
 
OICX Retail Customer Experience
OICX Retail Customer ExperienceOICX Retail Customer Experience
OICX Retail Customer Experience
Damian Kernahan
 
Monomictic lakes francisco muñoz maestre
Monomictic lakes francisco muñoz maestreMonomictic lakes francisco muñoz maestre
Monomictic lakes francisco muñoz maestre
Francisco Maestre
 
Abc c program
Abc c programAbc c program
Abc c program
Dayakar Siddula
 
Hybrid-Active-Optical-Cable-White-Paper
Hybrid-Active-Optical-Cable-White-PaperHybrid-Active-Optical-Cable-White-Paper
Hybrid-Active-Optical-Cable-White-Paper
Nguyen Nguyen
 
Ngaputaw ppt
Ngaputaw pptNgaputaw ppt
Ngaputaw ppt
Thurein Naywinaung
 
Statement to Guardian
Statement to GuardianStatement to Guardian
Statement to Guardian
Aristides Hatzis
 
Aula 1 a obra de kant como síntese do nascente pensamento burguês
Aula 1   a obra de kant como síntese do nascente pensamento burguêsAula 1   a obra de kant como síntese do nascente pensamento burguês
Aula 1 a obra de kant como síntese do nascente pensamento burguês
Leandro Alano
 
Sun & VMware Desktop Training
Sun & VMware Desktop TrainingSun & VMware Desktop Training
Sun & VMware Desktop Training
Matthias Mueller-Prove
 
Introduction to css part1
Introduction to css part1Introduction to css part1
Introduction to css part1
Khem Puthea
 
Membuat partisi di os windows
Membuat partisi di os windowsMembuat partisi di os windows
Membuat partisi di os windows
Nugroho Setiawan
 
Facebook Tackle Box: 10 Apps & Tools Every Brand Should Use
Facebook Tackle Box: 10 Apps & Tools Every Brand Should UseFacebook Tackle Box: 10 Apps & Tools Every Brand Should Use
Facebook Tackle Box: 10 Apps & Tools Every Brand Should Use
Firebelly Marketing
 
Q2 2013 ASSA ABLOY investors presentation 19 july
Q2 2013 ASSA ABLOY investors presentation 19 julyQ2 2013 ASSA ABLOY investors presentation 19 july
Q2 2013 ASSA ABLOY investors presentation 19 july
ASSA ABLOY
 
Time Management within IT Project Management
Time Management within IT Project ManagementTime Management within IT Project Management
Time Management within IT Project Management
rielaantonio
 
OICX Retail Customer Experience
OICX Retail Customer ExperienceOICX Retail Customer Experience
OICX Retail Customer Experience
Damian Kernahan
 
Monomictic lakes francisco muñoz maestre
Monomictic lakes francisco muñoz maestreMonomictic lakes francisco muñoz maestre
Monomictic lakes francisco muñoz maestre
Francisco Maestre
 
Hybrid-Active-Optical-Cable-White-Paper
Hybrid-Active-Optical-Cable-White-PaperHybrid-Active-Optical-Cable-White-Paper
Hybrid-Active-Optical-Cable-White-Paper
Nguyen Nguyen
 
Aula 1 a obra de kant como síntese do nascente pensamento burguês
Aula 1   a obra de kant como síntese do nascente pensamento burguêsAula 1   a obra de kant como síntese do nascente pensamento burguês
Aula 1 a obra de kant como síntese do nascente pensamento burguês
Leandro Alano
 
Ad

Similar to Php using variables-operators (20)

PHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP n
PHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP nPHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP n
PHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP n
ArtiRaju1
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
Saraswathi Murugan
 
Php
PhpPhp
Php
Rajkiran Mummadi
 
IT2255 Web Essentials - Unit IV Server-Side Processing and Scripting - PHP.pdf
IT2255 Web Essentials - Unit IV Server-Side Processing and Scripting - PHP.pdfIT2255 Web Essentials - Unit IV Server-Side Processing and Scripting - PHP.pdf
IT2255 Web Essentials - Unit IV Server-Side Processing and Scripting - PHP.pdf
pkaviya
 
Unit IV.pptx Server side scripting PHP IT3401
Unit IV.pptx Server side scripting PHP IT3401Unit IV.pptx Server side scripting PHP IT3401
Unit IV.pptx Server side scripting PHP IT3401
lakshitakumar291
 
Vision academy classes bcs_bca_bba_sybba_php
Vision academy  classes bcs_bca_bba_sybba_phpVision academy  classes bcs_bca_bba_sybba_php
Vision academy classes bcs_bca_bba_sybba_php
sachin892777
 
Chapter 4 server side Php Haypertext P.pptx
Chapter 4 server side Php Haypertext P.pptxChapter 4 server side Php Haypertext P.pptx
Chapter 4 server side Php Haypertext P.pptx
KelemAlebachew
 
Web Technology_10.ppt
Web Technology_10.pptWeb Technology_10.ppt
Web Technology_10.ppt
Aftabali702240
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
Muthuganesh S
 
PHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP n
PHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP nPHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP n
PHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP n
ArtiRaju1
 
Learn PHP Basics
Learn PHP Basics Learn PHP Basics
Learn PHP Basics
McSoftsis
 
Synapse india complain sharing info about php chaptr 26
Synapse india complain sharing info about php chaptr 26Synapse india complain sharing info about php chaptr 26
Synapse india complain sharing info about php chaptr 26
SynapseindiaComplaints
 
Php introduction
Php introductionPhp introduction
Php introduction
Pratik Patel
 
Php modul-1
Php modul-1Php modul-1
Php modul-1
Kristophorus Hadiono
 
Intro to php
Intro to phpIntro to php
Intro to php
NithyaNithyav
 
Intoroduction to Adnvanced Internet Programming Chapter two.pptx
Intoroduction to Adnvanced Internet Programming Chapter two.pptxIntoroduction to Adnvanced Internet Programming Chapter two.pptx
Intoroduction to Adnvanced Internet Programming Chapter two.pptx
JerusalemFetene
 
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
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards
Denis Ristic
 
Php intro by sami kz
Php intro by sami kzPhp intro by sami kz
Php intro by sami kz
sami2244
 
PHP-Part1
PHP-Part1PHP-Part1
PHP-Part1
Ahmed Saihood
 
PHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP n
PHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP nPHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP n
PHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP n
ArtiRaju1
 
IT2255 Web Essentials - Unit IV Server-Side Processing and Scripting - PHP.pdf
IT2255 Web Essentials - Unit IV Server-Side Processing and Scripting - PHP.pdfIT2255 Web Essentials - Unit IV Server-Side Processing and Scripting - PHP.pdf
IT2255 Web Essentials - Unit IV Server-Side Processing and Scripting - PHP.pdf
pkaviya
 
Unit IV.pptx Server side scripting PHP IT3401
Unit IV.pptx Server side scripting PHP IT3401Unit IV.pptx Server side scripting PHP IT3401
Unit IV.pptx Server side scripting PHP IT3401
lakshitakumar291
 
Vision academy classes bcs_bca_bba_sybba_php
Vision academy  classes bcs_bca_bba_sybba_phpVision academy  classes bcs_bca_bba_sybba_php
Vision academy classes bcs_bca_bba_sybba_php
sachin892777
 
Chapter 4 server side Php Haypertext P.pptx
Chapter 4 server side Php Haypertext P.pptxChapter 4 server side Php Haypertext P.pptx
Chapter 4 server side Php Haypertext P.pptx
KelemAlebachew
 
PHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP n
PHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP nPHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP n
PHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP n
ArtiRaju1
 
Learn PHP Basics
Learn PHP Basics Learn PHP Basics
Learn PHP Basics
McSoftsis
 
Synapse india complain sharing info about php chaptr 26
Synapse india complain sharing info about php chaptr 26Synapse india complain sharing info about php chaptr 26
Synapse india complain sharing info about php chaptr 26
SynapseindiaComplaints
 
Intoroduction to Adnvanced Internet Programming Chapter two.pptx
Intoroduction to Adnvanced Internet Programming Chapter two.pptxIntoroduction to Adnvanced Internet Programming Chapter two.pptx
Intoroduction to Adnvanced Internet Programming Chapter two.pptx
JerusalemFetene
 
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
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards
Denis Ristic
 
Php intro by sami kz
Php intro by sami kzPhp intro by sami kz
Php intro by sami kz
sami2244
 
Ad

Recently uploaded (20)

MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Respiratory System , Urinary System
Respiratory  System , Urinary SystemRespiratory  System , Urinary System
Respiratory System , Urinary System
RushiMandali
 
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
Quiz Club of PSG College of Arts & Science
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptxCapitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdfUnit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptxWhat is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
How to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 SalesHow to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 Sales
Celine George
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptxUnit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition OecdEnergy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Respiratory System , Urinary System
Respiratory  System , Urinary SystemRespiratory  System , Urinary System
Respiratory System , Urinary System
RushiMandali
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptxCapitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdfUnit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptxWhat is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
How to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 SalesHow to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 Sales
Celine George
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptxUnit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition OecdEnergy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 

Php using variables-operators

  • 2. Part I: Understanding PHP Basics Using Variables and Operators Prepared by KhmerCourse
  • 3. Storing Data in Variables ៚ Some simple rules for naming variables ៙ Be preceded with a dollar symbol $ ៙ And begin with a letter or underscore _ ៙ Optionally followed by more letters, numbers, or underscore ៙ Be not permitted ៜ Punctuation: commas ,, quotation marks ?, or periods . ៜ Spaces ៙ e.g. ៜ $id, $_name and $query3: valid ៜ $96, $day. and email: invalid ៚ Variable names are case-sensitive. ៙ e.g. $name and $Name refer to different variables. 3
  • 4. Assigning Values to Variables ៚ $var = val; ៙ e.g. assigningValues2Variables.php <?php $language = "PHP"; ?> <h1>Welcome <?php echo $language; ?></h1> ៚ Dynamic variable's name ៙ e.g. dynamicVariableName.php <?php $clone = "real"; // create a value of ${$clone} = echo $real; ?> new variable dynamically $clone "REAL"; // output: REAL at run time from the Is it possible for a variable's name itself to be a variable? ៚ echo(): print the value of a variable 4
  • 5. Destroying Variables ៚ e.g. destroyingVariables.php <?php $apple = "Apple"; echo $apple; // output: Apple // unset() unset($apple); echo $apple; // error: Undefined variable $banana = "Banana"; echo $banana; // // NULL value $banana = NULL; echo $banana; // ?> output: Banana output: (nothing) 5
  • 6. Inspecting Variable Contents ៚ e.g. inspectingVariableContents.php <?php $apple = "Apple"; $yr = 2011; // var_dump() var_dump($apple); var_dump($yr); // // output: string(5) output: int(2011) "Apple" // print_r() print_r($apple); // output: Apple print_r($yr); ?> // output: 2011 6
  • 7. Understanding PHP’s Data Types ៚ Data type is the values assigned to a variable. ៚ Booleans ៙ 1 (true) or 0 (false) ៚ 2 numeric ៙ Floating-point values (a.k.a floats or doubles) are decimal or fractional numbers, ៙ While integers are round numbers. ៚ Non-numeric: String ៙ Be enclosed in single quotes (') or double quotes (") ៚ NULL (a special data type in PHP4) ៙ Represent empty variables; a variable of type NULL is a variable without any data. A NULL value is not equivalent to an empty string "". 7
  • 8. Understanding PHP’s Data Types (cont.) ៚ e.g. hexadecimal_octal_scientificNotation.php <?php $dec echo = 8; // decimal $dec; // output: 8 $oct echo = 010; // octal $oct; // output: 8 $hex echo = 0x5dc; $hex; // // hexadecimal output: 1500 // scientific notation $sn1 $sn2 echo ?> = 6.9e+2; = 6.9e-2; $sn1." ".$sn2; // output: 690 0.069 8
  • 9. Setting and Checking Variable Data Types ៚ e.g. setting_CheckingVariableDataTypes.php <?php $apple = "Apple"; echo gettype($apple); // output: string $yr = 2011; echo gettype($yr); // output: integer $valid = true; echo gettype($valid); // output : boolean echo gettype($banana); // output: NULL variable) (error: Undefined $empty = NULL; echo gettype($empty); // output: NULL ?> 9
  • 10. Setting and Checking Variable Data Types (cont.) ៚ e.g. casting.php <?php $f_speed = $i_speed = // output: 36.9; // floating-point (integer) 36.9 $f_speed; // cast to integer echo $f_speed; // output: 36 echo ?> $i_speed;; 10 Data Type Checking Functions Function Purpose is_bool Test if holding a Boolean value is_numeric Test if holding a numeric value is_int Test if holding an integer value is_float Test if holding a float value is_string Test if holding a string value is_null Test if holding a NULL value is_array Test if being an array is_object Test if being an object
  • 11. Using Constants ៚ define(CONST, val); ៚ Constant names follows the same rules as variable names but not the $ ៚ e.g. usingConstants.php <?php define("APPLE", "Apple"); define("YR", 2011); prefix. // output: Apple 2011 echo ?> APPLE." ".YR; Constants name are usually entirely UPPERCASED. When should we use a variable, and when should we use a constant? 11
  • 12. Manipulating Variables with Operators ៚ Operators are symbols that tell the PHP processor to perform certain actions. ៚ PHP supports more than 50 such operators, ranging from operators for arithmetical operations to operators for logical comparison and bitwise calculations. 12
  • 13. Performing Arithmetic Operations ៚ e.g. arithmeticOperations.php <?php echo 3 + 2; // output: 5 echo 3 - 2; // output: 1 echo 3 * 2; // output: 6 echo 3 / 2; // output: 1.5 echo ?> 3 % 2; // output: 1 Is there any limit on how large a PHP integer value can be? 13 Arithmetic Operators Operator Description + Add - Subtract * Multiply / Divide % Modulus
  • 14. Concatenating Strings ៚ e.g. concatenatingStrings.php <?php $apple = "Apple"; $banana = "Banana"; // use (.) to join strings into 1 $fruits = $apple." and ".$banana; // output: I love apple and ".$fruits."."; banana.. echo ?> "I love 14
  • 15. Comparing Variables ៚ e.g. comparingVariables.php <?php $num = 6; $num2 = 3; $str = "6"; // output: echo ($num // output: echo ($num 0 < 1 > (false) $num2); (true) $num2); // output: echo ($num 0 < (false) $str); // output: echo ($num // output: echo ($num ?> 1 (true) == $str); 0 (false) === $str); 15 Comparison Operators Operator Description == Equal to != Not equal to > Greater than >= Greater than or equal to < Less than <= Less than or equal to === Equal to and of the same type
  • 16. Performing Logical Tests ៚ e.g. performingLogicalTests.php <?php // output: echo (true // output: echo (true // output: 1 (true) && true); 0 (false) && false); 0 (false) echo (false && false); // output: 1 (true) echo (false || true); // output: 0 (false) echo (!true); ?> 16 Logical Operators Operator Description && AND || OR ! NOT
  • 17. Other Useful Operators ៚ e.g. otherUsefulOperators.php <?php $count = 7; $age = 60; $greet = "We"; Increased by 1: ++ Decreased by 1: -- $count -= 2; // output: 5 echo $count; e.g. $count++; // $count = $count + 1; $age /= 5; // output: 12 echo $age; $greet .= "lcome!"; // output: Welcome! echo $greet; ?> 17 Assignment Operators Operator Description += Add, assign -= Subtract, assign *= Multiply, assign /= Divide, assign %= Modulus, assign .= Concatenate, assign
  • 18. Understanding Operator Precedence ៚ Operators at the same level have equal precedence: ៙ ++ ៙ ! ៙ * ៙ + ៙ < ៙ == ៙ && ៙ || ៙ = -- / - <= != % . > >= === !== += -= *= /= .= %= &= |= ^= ៚ Parentheses ( ៚ e.g. ៙ 3 + 2 * ៙ (3 + 2) ): force PHP to evaluate it first 5; // 3 + 10 = 13 * 5; // 5 * 5 = 25 18
  • 19. Handling Form Input ៚ e.g. chooseCar.html <form name="fCar" method="POST" action="getCar.php"> <select name="selType"> <option value="Porsche">Porsche</option> <option value="Ford">Ford</option> </select> Color: <input <input </form> type="text" name="txtColor" /> type="submit" value="get Car" /> action="getCar.php" Reference a PHP script method="POST" Submission via POST GET: method="GET" 19
  • 20. Handling Form Input (cont.) ៚ e.g. getCar.php <?php // get values via $_POST | $_GET $type = $_POST["selType"]; $color = $_POST["txtColor"]; echo $color." ".$type; ?> $_POST[fieldName]; $_POST: a special container variable (array) is used to get a value of a field of a form sent by using the POST method (or $_GET for the GET method). fieldName: the field whose value will be get/assigned to a variable. 20