SlideShare a Scribd company logo
1 of 24
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

What's hot

Web app development_php_04
Web app development_php_04Web app development_php_04
Web app development_php_04
Hassen Poreya
 

What's hot (20)

Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Data Types In PHP
Data Types In PHPData Types In PHP
Data Types In PHP
 
Variables in PHP
Variables in PHPVariables in PHP
Variables in PHP
 
Class 8 - Database Programming
Class 8 - Database ProgrammingClass 8 - Database Programming
Class 8 - Database Programming
 
Class 2 - Introduction to PHP
Class 2 - Introduction to PHPClass 2 - Introduction to PHP
Class 2 - Introduction to PHP
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 
Sorting arrays in PHP
Sorting arrays in PHPSorting arrays in PHP
Sorting arrays in PHP
 
PHP Variables and scopes
PHP Variables and scopesPHP Variables and scopes
PHP Variables and scopes
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
Basic PHP
Basic PHPBasic PHP
Basic PHP
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & Arrays
 
slidesharenew1
slidesharenew1slidesharenew1
slidesharenew1
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!
 
Php 101 by David Menendez
Php 101 by David MenendezPhp 101 by David Menendez
Php 101 by David Menendez
 
php basics
php basicsphp basics
php basics
 
PHP Training Part1
PHP Training Part1PHP Training Part1
PHP Training Part1
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Basic of PHP
Basic of PHPBasic of PHP
Basic of PHP
 
Web app development_php_04
Web app development_php_04Web app development_php_04
Web app development_php_04
 

Viewers also liked

güncel referanslar mail eki
güncel referanslar mail ekigüncel referanslar mail eki
güncel referanslar mail eki
samet sahin
 
Republicanism vs Multiculturalism - A critical analysis of the French system ...
Republicanism vs Multiculturalism - A critical analysis of the French system ...Republicanism vs Multiculturalism - A critical analysis of the French system ...
Republicanism vs Multiculturalism - A critical analysis of the French system ...
Mélanie Rieder
 
Simpsons Coating Presentation
Simpsons Coating PresentationSimpsons Coating Presentation
Simpsons Coating Presentation
Vinay Gupta
 

Viewers also liked (15)

FinalCV
FinalCVFinalCV
FinalCV
 
Prezentacja - Motywacja uczniów do nauki
Prezentacja - Motywacja uczniów do naukiPrezentacja - Motywacja uczniów do nauki
Prezentacja - Motywacja uczniów do nauki
 
Cinemática 1 D
Cinemática 1 DCinemática 1 D
Cinemática 1 D
 
El arte de tejer presentación power point
El arte de tejer   presentación power pointEl arte de tejer   presentación power point
El arte de tejer presentación power point
 
güncel referanslar mail eki
güncel referanslar mail ekigüncel referanslar mail eki
güncel referanslar mail eki
 
Tipos de la conducta
Tipos de la conductaTipos de la conducta
Tipos de la conducta
 
z heuwel Cv
z heuwel Cvz heuwel Cv
z heuwel Cv
 
zero conditional
zero conditionalzero conditional
zero conditional
 
プレゼンテーション2
プレゼンテーション2プレゼンテーション2
プレゼンテーション2
 
Trabajo de construccion
Trabajo de construccionTrabajo de construccion
Trabajo de construccion
 
Resume Austine
Resume AustineResume Austine
Resume Austine
 
Republicanism vs Multiculturalism - A critical analysis of the French system ...
Republicanism vs Multiculturalism - A critical analysis of the French system ...Republicanism vs Multiculturalism - A critical analysis of the French system ...
Republicanism vs Multiculturalism - A critical analysis of the French system ...
 
Simpsons Coating Presentation
Simpsons Coating PresentationSimpsons Coating Presentation
Simpsons Coating Presentation
 
Rod Res 1
Rod Res 1Rod Res 1
Rod Res 1
 
No Regrets Project
No Regrets ProjectNo Regrets Project
No Regrets Project
 

Similar to Php introduction

P H P Part I, By Kian
P H P  Part  I,  By  KianP H P  Part  I,  By  Kian
P H P Part I, By Kian
phelios
 

Similar to Php introduction (20)

Learn PHP Basics
Learn PHP Basics Learn PHP Basics
Learn PHP Basics
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards
 
OpenGurukul : Language : PHP
OpenGurukul : Language : PHPOpenGurukul : Language : PHP
OpenGurukul : Language : PHP
 
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
 
unit 1.pptx
unit 1.pptxunit 1.pptx
unit 1.pptx
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
PHP Basic
PHP BasicPHP Basic
PHP Basic
 
FYBSC IT Web Programming Unit IV PHP and MySQL
FYBSC IT Web Programming Unit IV  PHP and MySQLFYBSC IT Web Programming Unit IV  PHP and MySQL
FYBSC IT Web Programming Unit IV PHP and MySQL
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Expressions and Operators.pptx
Expressions and Operators.pptxExpressions and Operators.pptx
Expressions and Operators.pptx
 
PHP-Part1
PHP-Part1PHP-Part1
PHP-Part1
 
Php essentials
Php essentialsPhp essentials
Php essentials
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Php
PhpPhp
Php
 
P H P Part I, By Kian
P H P  Part  I,  By  KianP H P  Part  I,  By  Kian
P H P Part I, By Kian
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
Free PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in IndiaFree PHP Book Online | PHP Development in India
Free PHP Book Online | PHP Development in India
 
Php assignment help
Php assignment helpPhp assignment help
Php assignment help
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1Web Development Course: PHP lecture 1
Web Development Course: PHP lecture 1
 

Recently uploaded

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

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
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
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
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

Php introduction

  • 1.
  • 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