SlideShare a Scribd company logo
Php introduction
PHP Syntax
 A PHP script starts with
<?php
and ends with
?>
<?php
echo "Hello World!";
?>
PHP Variables
 In PHP, a variable starts with the $ sign, followed by the
name of the variable
 <?php
$txt = "Hello world!";
$x = 5;
$y = 10.5;
?>
 Rules for PHP variables:
 A variable starts with the $ sign, followed by the name of the
variable
 A variable name must start with a letter or the underscore
character
 A variable name cannot start with a number
 A variable name can only contain alpha-numeric characters and
underscores (A-z, 0-9, and _ )
 Variable names are case-sensitive ($age and $AGE are two
different variables)
PHP echo and print Statements
 echo and print are more or less the
same. They are both used to output data
to the screen.
 The differences are small: echo has no
return value while print has a return
value of 1 so it can be used in
expressions. echo can take multiple
parameters (although such usage is
rare) while print can take one argument.
echo is marginally faster than print.
PHP echo and print Statements
 <?php
$txt1 = "Learn PHP";
$txt2 = "W3Schools.com";
$x = 5;
$y = 4;
echo "<h2>$txt1</h2>";
echo "Study PHP at $txt2<br>";
print($txt2 );
?>
PHP Data Types
 Variables can store data of different types, and
different data types can do different things.
 PHP supports the following data types:
 String
 Integer
 Float (floating point numbers - also called
double)
 Boolean
 Array
 Object
 NULL
PHP String
 <?php
$x = "Hello world!";
$y = 'Hello world!';
echo $x;
echo "<br>";
echo $y;
?>
PHP Integer
 <?php
$x = 5985;
var_dump($x);
?>
PHP Float
 <?php
$x = 10.365;
var_dump($x);
?>
PHP Boolean
 $x = true;
$y = false;
PHP Array
 An array stores multiple values in one
single variable.
 <?php
$cars = array("Volvo","BMW","Toyota");
var_dump($cars);
?>
PHP Object
 $object =
json_decode(json_encode($array),
FALSE);
 $object = (object) $array_name; //now it
is converted to object and you can
access it.
 echo $object->username;
PHP NULL Value
 Null is a special data type which can have only one
value: NULL.
 A variable of data type NULL is a variable that has no
value assigned to it.
 Tip: If a variable is created without a value, it is
automatically assigned a value of NULL.
 Variables can also be emptied by setting the value to
NULL:
 <?php
$x = "Hello world!";
$x = null;
var_dump($x);
?>
PHP Constants
 A constant is an identifier (name) for a
simple value. The value cannot be
changed during the script.
 A valid constant name starts with a letter
or underscore (no $ sign before the
constant name).
 Note: Unlike variables, constants are
automatically global across the entire
script.
PHP Constants
 To create a constant, use the define()
function.
 Syntax :
define(name, value, case-insensitive)
 <?php
define("GREETING", "Welcome to
W3Schools.com!", true);
echo greeting;
?>
PHP 5 Operators
 PHP Operators
 Operators are used to perform operations on
variables and values.
 PHP divides the operators in the following groups:
 Arithmetic operators
 Assignment operators
 Comparison operators
 Increment/Decrement operators
 Logical operators
 String operators
 Array operators
PHP Arithmetic Operators
Operator Name Example Result
+ Addition $x + $y Sum of $x and
$y
- Subtraction $x - $y Difference of $x
and $y
* Multiplication $x * $y Product of $x
and $y
/ Division $x / $y Quotient of $x
and $y
% Modulus $x % $y Remainder of $x
divided by $y
** Exponentiation $x ** $y Result of raising
$x to the $y'th
power
(Introduced in
PHP 5.6)
PHP Assignment Operators
Assignment Same as... Description
x = y x = y The left operand gets
set to the value of the
expression on the
right
x += y x = x + y Addition
x -= y x = x - y Subtraction
x *= y x = x * y Multiplication
x /= y x = x / y Division
x %= y x = x % y Modulus
PHP Comparison Operators
Operator Name Example
== Equal $x == $y
=== Identical $x === $y
!= Not equal $x != $y
<> Not equal $x <> $y
!== Not identical $x !== $y
> Greater than $x > $y
< Less than $x < $y
>= Greater than or equal
to
$x >= $y
<= Less than or equal to $x <= $y
PHP Increment / Decrement
Operators
 The PHP increment operators are used
to increment a variable's value.
 The PHP decrement operators are used
to decrement a variable's value.
PHP Increment / Decrement
Operators
 The PHP increment operators are used
to increment a variable's value.
 The PHP decrement operators are used
to decrement a variable's value.
Operator Name Description
++$x Pre-increment Increments $x by
one, then returns $x
$x++ Post-increment Returns $x, then
increments $x by one
--$x Pre-decrement Decrements $x by
one, then returns $x
$x-- Post-decrement Returns $x, then
decrements $x by
one
PHP Logical Operators
 The PHP logical operators are used to
combine conditional statements.
Operator Name Example
and And $x and $y
or Or $x or $y
xor Xor $x xor $y
&& And $x && $y
|| Or $x || $y
! Not !$x
PHP String Operators
 PHP has two operators that are
specially designed for strings.
Operator Name Example
. Concatenation $txt1 . $txt2
.= Concatenation
assignment
$txt1 .= $txt2
PHP Array Operators
Operator Name Example
+ Union $x + $y
== Equality $x == $y
=== Identity $x === $y
!= Inequality $x != $y
<> Inequality $x <> $y
!== Non-identity $x !== $y

More Related Content

PPT
PHP variables
Siddique Ibrahim
 
PPTX
Operators php
Chandni Pm
 
PPT
Php variables
Ritwik Das
 
ODP
Php variables (english)
Mahmoud Masih Tehrani
 
PPT
PHP - DataType,Variable,Constant,Operators,Array,Include and require
TheCreativedev Blog
 
PDF
Operators in PHP
Vineet Kumar Saini
 
PPTX
Variables
Suraj Motee
 
PPSX
Php using variables-operators
Khem Puthea
 
PHP variables
Siddique Ibrahim
 
Operators php
Chandni Pm
 
Php variables
Ritwik Das
 
Php variables (english)
Mahmoud Masih Tehrani
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
TheCreativedev Blog
 
Operators in PHP
Vineet Kumar Saini
 
Variables
Suraj Motee
 
Php using variables-operators
Khem Puthea
 

What's hot (20)

PPTX
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
anshkhurana01
 
PPTX
PHP Basics
Saraswathi Murugan
 
PDF
Data Types In PHP
Mark Niebergall
 
PDF
Variables in PHP
Vineet Kumar Saini
 
PPTX
Class 8 - Database Programming
Ahmed Swilam
 
PPT
Class 2 - Introduction to PHP
Ahmed Swilam
 
PDF
Php Tutorials for Beginners
Vineet Kumar Saini
 
PDF
Sorting arrays in PHP
Vineet Kumar Saini
 
PPTX
PHP Variables and scopes
sana mateen
 
PPT
Php i basic chapter 3
Muhamad Al Imran
 
PPT
Basic PHP
Todd Barber
 
PPTX
PHP Functions & Arrays
Henry Osborne
 
PPT
slidesharenew1
truptitasol
 
PPT
My cool new Slideshow!
omprakash_bagrao_prdxn
 
PPTX
Php 101 by David Menendez
dm09f
 
PPTX
php basics
Anmol Paul
 
PPTX
PHP Training Part1
than sare
 
PPTX
PHP Basics
Bhaktaraz Bhatta
 
PPTX
Basic of PHP
Nisa Soomro
 
PDF
Web app development_php_04
Hassen Poreya
 
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
anshkhurana01
 
PHP Basics
Saraswathi Murugan
 
Data Types In PHP
Mark Niebergall
 
Variables in PHP
Vineet Kumar Saini
 
Class 8 - Database Programming
Ahmed Swilam
 
Class 2 - Introduction to PHP
Ahmed Swilam
 
Php Tutorials for Beginners
Vineet Kumar Saini
 
Sorting arrays in PHP
Vineet Kumar Saini
 
PHP Variables and scopes
sana mateen
 
Php i basic chapter 3
Muhamad Al Imran
 
Basic PHP
Todd Barber
 
PHP Functions & Arrays
Henry Osborne
 
slidesharenew1
truptitasol
 
My cool new Slideshow!
omprakash_bagrao_prdxn
 
Php 101 by David Menendez
dm09f
 
php basics
Anmol Paul
 
PHP Training Part1
than sare
 
PHP Basics
Bhaktaraz Bhatta
 
Basic of PHP
Nisa Soomro
 
Web app development_php_04
Hassen Poreya
 
Ad

Viewers also liked (15)

DOC
FinalCV
Ayman Shokry
 
PPT
Prezentacja - Motywacja uczniów do nauki
Agnieszka Pie
 
DOCX
Cinemática 1 D
Edwin SB
 
PPTX
El arte de tejer presentación power point
Universidad de Murcia
 
PDF
güncel referanslar mail eki
samet sahin
 
PPTX
Tipos de la conducta
Gladys López
 
DOCX
z heuwel Cv
zanda-lee Heuwel
 
PPTX
zero conditional
maria fernanda guzman calvo
 
PPTX
プレゼンテーション2
hiroaki furusho
 
DOCX
Trabajo de construccion
Desiree Velazco
 
PDF
Resume Austine
Austine Okeyo
 
PDF
Republicanism vs Multiculturalism - A critical analysis of the French system ...
Mélanie Rieder
 
PDF
Simpsons Coating Presentation
Vinay Gupta
 
RTF
Rod Res 1
Rod Jones
 
PPTX
No Regrets Project
Kitty Edwards
 
FinalCV
Ayman Shokry
 
Prezentacja - Motywacja uczniów do nauki
Agnieszka Pie
 
Cinemática 1 D
Edwin SB
 
El arte de tejer presentación power point
Universidad de Murcia
 
güncel referanslar mail eki
samet sahin
 
Tipos de la conducta
Gladys López
 
z heuwel Cv
zanda-lee Heuwel
 
zero conditional
maria fernanda guzman calvo
 
プレゼンテーション2
hiroaki furusho
 
Trabajo de construccion
Desiree Velazco
 
Resume Austine
Austine Okeyo
 
Republicanism vs Multiculturalism - A critical analysis of the French system ...
Mélanie Rieder
 
Simpsons Coating Presentation
Vinay Gupta
 
Rod Res 1
Rod Jones
 
No Regrets Project
Kitty Edwards
 
Ad

Similar to Php introduction (20)

PPTX
PHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP n
ArtiRaju1
 
PPTX
PHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP n
ArtiRaju1
 
PPTX
Learn PHP Basics
McSoftsis
 
PDF
07 Introduction to PHP #burningkeyboards
Denis Ristic
 
PPTX
Unit IV.pptx Server side scripting PHP IT3401
lakshitakumar291
 
ODP
OpenGurukul : Language : PHP
Open Gurukul
 
PDF
IT2255 Web Essentials - Unit IV Server-Side Processing and Scripting - PHP.pdf
pkaviya
 
PPTX
unit 1.pptx
adityathote3
 
PPTX
PHP BASICs Data Type ECHo and PRINT.pptx
ChandrashekharSingh859453
 
PPTX
PHP Basics
Muthuganesh S
 
ODP
PHP Basic
Yoeung Vibol
 
PPTX
FYBSC IT Web Programming Unit IV PHP and MySQL
Arti Parab Academics
 
PPTX
Introduction to php
Taha Malampatti
 
PPTX
Expressions and Operators.pptx
Japneet9
 
PPTX
Intoroduction to Adnvanced Internet Programming Chapter two.pptx
JerusalemFetene
 
PDF
PHP-Part1
Ahmed Saihood
 
PPT
Php essentials
sagaroceanic11
 
PPTX
Introduction to Java
yzebelle
 
PPTX
Data types and variables in php for writing
vishal choudhary
 
PPTX
Php
Yoga Raja
 
PHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP n
ArtiRaju1
 
PHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP n
ArtiRaju1
 
Learn PHP Basics
McSoftsis
 
07 Introduction to PHP #burningkeyboards
Denis Ristic
 
Unit IV.pptx Server side scripting PHP IT3401
lakshitakumar291
 
OpenGurukul : Language : PHP
Open Gurukul
 
IT2255 Web Essentials - Unit IV Server-Side Processing and Scripting - PHP.pdf
pkaviya
 
unit 1.pptx
adityathote3
 
PHP BASICs Data Type ECHo and PRINT.pptx
ChandrashekharSingh859453
 
PHP Basics
Muthuganesh S
 
PHP Basic
Yoeung Vibol
 
FYBSC IT Web Programming Unit IV PHP and MySQL
Arti Parab Academics
 
Introduction to php
Taha Malampatti
 
Expressions and Operators.pptx
Japneet9
 
Intoroduction to Adnvanced Internet Programming Chapter two.pptx
JerusalemFetene
 
PHP-Part1
Ahmed Saihood
 
Php essentials
sagaroceanic11
 
Introduction to Java
yzebelle
 
Data types and variables in php for writing
vishal choudhary
 

Recently uploaded (20)

PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PDF
Software Development Methodologies in 2025
KodekX
 
PPTX
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
PDF
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
CIFDAQ
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PDF
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
CIFDAQ
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Software Development Methodologies in 2025
KodekX
 
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
CIFDAQ
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
CIFDAQ
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 

Php introduction

  • 2. PHP Syntax  A PHP script starts with <?php and ends with ?> <?php echo "Hello World!"; ?>
  • 3. PHP Variables  In PHP, a variable starts with the $ sign, followed by the name of the variable  <?php $txt = "Hello world!"; $x = 5; $y = 10.5; ?>  Rules for PHP variables:  A variable starts with the $ sign, followed by the name of the variable  A variable name must start with a letter or the underscore character  A variable name cannot start with a number  A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )  Variable names are case-sensitive ($age and $AGE are two different variables)
  • 4. PHP echo and print Statements  echo and print are more or less the same. They are both used to output data to the screen.  The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters (although such usage is rare) while print can take one argument. echo is marginally faster than print.
  • 5. PHP echo and print Statements  <?php $txt1 = "Learn PHP"; $txt2 = "W3Schools.com"; $x = 5; $y = 4; echo "<h2>$txt1</h2>"; echo "Study PHP at $txt2<br>"; print($txt2 ); ?>
  • 6. PHP Data Types  Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer  Float (floating point numbers - also called double)  Boolean  Array  Object  NULL
  • 7. PHP String  <?php $x = "Hello world!"; $y = 'Hello world!'; echo $x; echo "<br>"; echo $y; ?>
  • 8. PHP Integer  <?php $x = 5985; var_dump($x); ?>
  • 9. PHP Float  <?php $x = 10.365; var_dump($x); ?>
  • 10. PHP Boolean  $x = true; $y = false;
  • 11. PHP Array  An array stores multiple values in one single variable.  <?php $cars = array("Volvo","BMW","Toyota"); var_dump($cars); ?>
  • 12. PHP Object  $object = json_decode(json_encode($array), FALSE);  $object = (object) $array_name; //now it is converted to object and you can access it.  echo $object->username;
  • 13. PHP NULL Value  Null is a special data type which can have only one value: NULL.  A variable of data type NULL is a variable that has no value assigned to it.  Tip: If a variable is created without a value, it is automatically assigned a value of NULL.  Variables can also be emptied by setting the value to NULL:  <?php $x = "Hello world!"; $x = null; var_dump($x); ?>
  • 14. PHP Constants  A constant is an identifier (name) for a simple value. The value cannot be changed during the script.  A valid constant name starts with a letter or underscore (no $ sign before the constant name).  Note: Unlike variables, constants are automatically global across the entire script.
  • 15. PHP Constants  To create a constant, use the define() function.  Syntax : define(name, value, case-insensitive)  <?php define("GREETING", "Welcome to W3Schools.com!", true); echo greeting; ?>
  • 16. PHP 5 Operators  PHP Operators  Operators are used to perform operations on variables and values.  PHP divides the operators in the following groups:  Arithmetic operators  Assignment operators  Comparison operators  Increment/Decrement operators  Logical operators  String operators  Array operators
  • 17. PHP Arithmetic Operators Operator Name Example Result + Addition $x + $y Sum of $x and $y - Subtraction $x - $y Difference of $x and $y * Multiplication $x * $y Product of $x and $y / Division $x / $y Quotient of $x and $y % Modulus $x % $y Remainder of $x divided by $y ** Exponentiation $x ** $y Result of raising $x to the $y'th power (Introduced in PHP 5.6)
  • 18. PHP Assignment Operators Assignment Same as... Description x = y x = y The left operand gets set to the value of the expression on the right x += y x = x + y Addition x -= y x = x - y Subtraction x *= y x = x * y Multiplication x /= y x = x / y Division x %= y x = x % y Modulus
  • 19. PHP Comparison Operators Operator Name Example == Equal $x == $y === Identical $x === $y != Not equal $x != $y <> Not equal $x <> $y !== Not identical $x !== $y > Greater than $x > $y < Less than $x < $y >= Greater than or equal to $x >= $y <= Less than or equal to $x <= $y
  • 20. PHP Increment / Decrement Operators  The PHP increment operators are used to increment a variable's value.  The PHP decrement operators are used to decrement a variable's value.
  • 21. PHP Increment / Decrement Operators  The PHP increment operators are used to increment a variable's value.  The PHP decrement operators are used to decrement a variable's value. Operator Name Description ++$x Pre-increment Increments $x by one, then returns $x $x++ Post-increment Returns $x, then increments $x by one --$x Pre-decrement Decrements $x by one, then returns $x $x-- Post-decrement Returns $x, then decrements $x by one
  • 22. PHP Logical Operators  The PHP logical operators are used to combine conditional statements. Operator Name Example and And $x and $y or Or $x or $y xor Xor $x xor $y && And $x && $y || Or $x || $y ! Not !$x
  • 23. PHP String Operators  PHP has two operators that are specially designed for strings. Operator Name Example . Concatenation $txt1 . $txt2 .= Concatenation assignment $txt1 .= $txt2
  • 24. PHP Array Operators Operator Name Example + Union $x + $y == Equality $x == $y === Identity $x === $y != Inequality $x != $y <> Inequality $x <> $y !== Non-identity $x !== $y