SlideShare a Scribd company logo
PHP (BASICS)
• PHP Defination
• PHP Syntax
• PHP Comments
• PHPVariables
• ECHO and PRINT
• PHP Datatypes
• PHP Constents
• PHP Operators
P H P
• PHP is a server scripting language, and a powerful tool for making
dynamic and interactive Web pages.
What is PHP?
• PHP is an acronym for "PHP: Hypertext Preprocessor"
• PHP is a widely-used, open source scripting language
• PHP scripts are executed on the server
• PHP is free to download and use
What is a PHP File?
• PHP files have extension ".php"
WHAT CAN PHP DO?
• PHP can generate dynamic page content
• PHP can create, open, read, write, delete, and close files on the server
• PHP can collect form data
• PHP can send and receive cookies
• PHP can add, delete, modify data in your database
• PHP can be used to control user-access
• PHP can encrypt data
P H P S Y N T A X P H P C O M M E N T S
<html>
<body>
<h1>My first PHP page</h1>
<?php
echo "Hello World!";
?>
</body>
</html>
// Outputs a welcome message:
echo "Welcome Home!";
Multi-line Comments
Multi-line comments start with /* and end with */.
Any text between /* and */ will be ignored.
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
• Variable names are case-sensitive
Example- $x = 5;
$y = "John"
P H P VA R I A B L E S S C O P E
The scope of a variable is the part of the script where the variable can be referenced/used.
PHP has three different variable scopes:
• local
• global
• static
GLOBAL AND LOCAL SCOPE
• A variable declared outside a function has a GLOBAL SCOPE and can only be accessed outside
a function.
Global Scope
<?php
$x = 5; // global scope
function myTest() {
// using x inside this function will generate an error
echo "<p>Variable x inside function is: $x</p>";
}
myTest();
echo "<p>Variable x outside function is: $x</p>";
?>
Output - Variable x inside function is:
Variable x outside function is: 5
LOCAL SCOPE
<?php
function myTest() {
$x = 5; // local scope
echo "<p>Variable x inside function is: $x</p>";
}
myTest();
// using x outside the function will generate an error
echo "<p>Variable x outside function is: $x</p>";
?>
Output - Variable x inside function is: 5
Variable x outside function is:
P H P E C H O A N D P R I N T S T A T E M E N T S
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.
P H P D A T A T Y P E S
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
• NULL
P H P S T R I N G
A string is a sequence of characters, like "Hello world!“.
<?php
$x = "Hello world!";
$y = 'Hello world!';
var_dump($x);
echo "<br>";
var_dump($y);
?>
Output - string(12) "Hello world!"
string(12) "Hello world!"
P H P I N T E G E R
• An integer must have at least one digit
• An integer must not have a decimal point
• An integer can be either positive or negative
• Integers can be specified in: decimal (base 10), hexadecimal (base 16), octal (base 8), or binary
(base 2) notation
<?php
$x = 5985;
var_dump($x);
?>
Output - int(5985)
PHP FLOAT
• A float (floating point number) is a number with a decimal point or a number in exponential form.
• In the following example $x is a float.The PHP var_dump() function returns the data type and
value:
<?php
$x = 10.365;
var_dump($x);
?>
Output - float(10.365)
PHP BOOLEAN
A Boolean represents two possible states:TRUE or FALSE.
<html>
<body>
<?php
$x = true;
var_dump($x);
?>
</body>
</html>
Output - bool(true)
P H P A R R A Y
• An array stores multiple values in one single variable.
• In the following example $cars is an array.The PHP var_dump() function returns the data type
and value:
<?php
$cars = array("BMW","Toyota");
var_dump($cars);
?>
Output –
array(2) { [0]=> string(3) "BMW" [1]=> string(6) "Toyota" }
P H P C A S T I N G
Change DataType
Casting in PHP is done with these statements:
(string) - Converts to data type String
(int) - Converts to data type Integer
(float) - Converts to data type Float
(bool) - Converts to data type Boolean
(array) - Converts to data type Array
(object) - Converts to data type Object
(unset) - Converts to data type NULL
<?php
$a="first step";
$b="2";
$c="true";
$d="3.89";
$f="null";
$a= (string) $a;
$b= (array) $b;
$c= (bool) $c;
$d= (float) $d;
$f= (string) $f;
//To verify the type of any object in PHP, use
the var_dump() funtion:
var_du($a);
echo"<br>";
var_dump($b);
echo"<br>";
var_dump($c);
echo"<br>";
var_dump($d);
echo"<br>";
var_dump($f);
?>
OUTPUT :
string(10) "first step"
array(1) { [0]=> string(1) "2" }
bool(true)
float(3.89)
string(4) "null"
P H P C O N S T A N T S
• Constants are like variables, except that once they are defined they cannot be
changed or undefined.
• 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)
Syntax:
define(name, value, case-insensitive);
P H P O P E R ATO R S
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
• Conditional assignment operators
PHP ARITHMETIC OPERATORS
The PHP arithmetic operators are used with numeric values to perform common
arithmetical operations, such as addition, subtraction, multiplication etc.
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
P H P A S S I G N M E N T O P E R AT O R S
The PHP assignment operators are used with numeric values to write a value to
a variable
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
P H P C O M PA R I S O N O P E R ATO R S
The PHP comparison operators are used to compare two values (number or string):
Operator Name Example Result
== Equal $x == $y Returns true if $x is equal to $y
=== Identical $x === $y Returns true if $x is equal to $y, and they are of the same
type
!= Not equal $x != $y Returns true if $x is not equal to $y
<> Not equal $x <> $y Returns true if $x is not equal to $y
!== Not identical $x !== $y Returns true if $x is not equal to $y, or they are not of the
same type
> Greater than $x > $y Returns true if $x is greater than $y
< Less than $x < $y Returns true if $x is less than $y
>= Greater than or equal to $x >= $y Returns true if $x is greater than or equal to $y
<= Less than or equal to $x <= $y Returns true if $x is less than or equal to $y
<=> Spaceship $x <=> $y Returns an integer less than, equal to, or greater than zero,
depending on if $x is less than, equal to, or greater than $y.
Introduced in PHP 7.
PH P IN CR E ME N T / D E CRE M EN T O PE R ATOR S
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 Same as... 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
P H P L O G I C A L O P E R AT O R S
The PHP logical operators are used to combine conditional statements.
Operator Name Example Result
and And $x and $y True if both $x and $y are true
or Or $x or $y True if either $x or $y is true
xor Xor $x xor $y True if either $x or $y is true, but not
both
&& And $x && $y True if both $x and $y are true
|| Or $x || $y True if either $x or $y is true
! Not !$x True if $x is not true
P H P S T R I N G O P E R AT O R S
PHP has two operators that are specially designed for strings.
Operator Name Example Result
. Concatenation $txt1 . $txt2 Concatenation of $txt1 and $txt2
.= Concatenation
assignment
$txt1 .= $txt2 Appends $txt2 to $txt1
P H P A R R AY O P E R ATO R S
The PHP array operators are used to compare arrays.
Operator Name Example Result
+ Union $x + $y Union of $x and $y
== Equality $x == $y Returns true if $x and $y have the same
key/value pairs
=== Identity $x === $y Returns true if $x and $y have the same
key/value pairs in the same order and of the
same types
!= Inequality $x != $y Returns true if $x is not equal to $y
<> Inequality $x <> $y Returns true if $x is not equal to $y
!== Non-identity $x !== $y Returns true if $x is not identical to $y
P H P C O N D I T I O N A L A S S I G N M E N T O P E R ATO R S
The PHP conditional assignment operators are used to set a value depending on
conditions:
Operator Name Example Result
?: Ternary $x
= expr1 ? expr2 : e
xpr3
Returns the value of $x.
The value of $x is expr2 if expr1 =
TRUE.
The value of $x is expr3 if expr1 =
FALSE
?? Null coalescing $x = expr1 ?? expr2 Returns the value of $x.
The value of $x
is expr1 if expr1 exists, and is not
NULL.
If expr1 does not exist, or is NULL,
the value of $x is expr2.
PHP IF STATEMENTS
if statement - executes some code if one condition is true.
<?php
if (5 > 3) {
echo "Have a good day!";
}
?>
Output - Have a good day!
P H P I F. . . E L S E S TAT E M E N T S
The if...else statement executes some code if a condition is true and another code if that condition is
false.
<?php
$t = date("H");
if ($t < "20") {
echo "Have a good day!";
} else {
echo "Have a good night!";
}
?>
Output - Have a good day!
I F. . . E LS E I F. . . E LS E S TAT E ME NT
The if...elseif...else statement executes different codes for more than two conditions.
<?php
if ($t < "10") {
echo "Have a good morning!";
} elseif ($t < "20") {
echo "Have a good day!";
} else {
echo "Have a good night!";
}
?>
Output - Have a good day!
THANK
YOU

More Related Content

Similar to PHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP n (20)

Php intro by sami kz
Php intro by sami kzPhp intro by sami kz
Php intro by sami kz
sami2244
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
Muthuganesh S
 
Php
PhpPhp
Php
Rajkiran Mummadi
 
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
 
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
 
data type in php and its introduction to use
data type in php and its introduction to usedata type in php and its introduction to use
data type in php and its introduction to use
vishal choudhary
 
Data types and variables in php for writing
Data types and variables in php for writingData types and variables in php for writing
Data types and variables in php for writing
vishal choudhary
 
Intro to php
Intro to phpIntro to php
Intro to php
NithyaNithyav
 
PHP Lecture 01 .pptx PHP Lecture 01 pptx
PHP Lecture 01 .pptx PHP Lecture 01 pptxPHP Lecture 01 .pptx PHP Lecture 01 pptx
PHP Lecture 01 .pptx PHP Lecture 01 pptx
shahgohar1
 
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
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
wahidullah mudaser
 
Operators php
Operators phpOperators php
Operators php
Chandni Pm
 
Php using variables-operators
Php using variables-operatorsPhp using variables-operators
Php using variables-operators
Khem Puthea
 
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 Scripting
PHP ScriptingPHP Scripting
PHP Scripting
Reem Alattas
 
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
 
Programming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th SemesterProgramming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th Semester
SanthiNivas
 
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
 
Working With Variables-[LAA] PHP Lj.pptx
Working With Variables-[LAA] PHP Lj.pptxWorking With Variables-[LAA] PHP Lj.pptx
Working With Variables-[LAA] PHP Lj.pptx
shahid41103
 
Php 26
Php 26Php 26
Php 26
Simratpreet Singh
 
Php intro by sami kz
Php intro by sami kzPhp intro by sami kz
Php intro by sami kz
sami2244
 
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
 
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
 
data type in php and its introduction to use
data type in php and its introduction to usedata type in php and its introduction to use
data type in php and its introduction to use
vishal choudhary
 
Data types and variables in php for writing
Data types and variables in php for writingData types and variables in php for writing
Data types and variables in php for writing
vishal choudhary
 
PHP Lecture 01 .pptx PHP Lecture 01 pptx
PHP Lecture 01 .pptx PHP Lecture 01 pptxPHP Lecture 01 .pptx PHP Lecture 01 pptx
PHP Lecture 01 .pptx PHP Lecture 01 pptx
shahgohar1
 
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
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
wahidullah mudaser
 
Php using variables-operators
Php using variables-operatorsPhp using variables-operators
Php using variables-operators
Khem Puthea
 
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
 
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
 
Programming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th SemesterProgramming in PHP Course Material BCA 6th Semester
Programming in PHP Course Material BCA 6th Semester
SanthiNivas
 
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
 
Working With Variables-[LAA] PHP Lj.pptx
Working With Variables-[LAA] PHP Lj.pptxWorking With Variables-[LAA] PHP Lj.pptx
Working With Variables-[LAA] PHP Lj.pptx
shahid41103
 

Recently uploaded (20)

SD160F Operator Manual PDF – Safety & Operation Guide Download.pdf
SD160F Operator Manual PDF – Safety & Operation Guide Download.pdfSD160F Operator Manual PDF – Safety & Operation Guide Download.pdf
SD160F Operator Manual PDF – Safety & Operation Guide Download.pdf
Service Repair Manual
 
Equipment Volvo EC480E Operator Manual.pdf
Equipment Volvo EC480E Operator Manual.pdfEquipment Volvo EC480E Operator Manual.pdf
Equipment Volvo EC480E Operator Manual.pdf
Service Repair Manual
 
SD190DX Operator Manual – Download User Instructions PDF.pdf
SD190DX Operator Manual – Download User Instructions PDF.pdfSD190DX Operator Manual – Download User Instructions PDF.pdf
SD190DX Operator Manual – Download User Instructions PDF.pdf
Service Repair Manual
 
WAY To JOIN REAL ILLUMINATI AGENT IN KAMPALA UGANDA CALL ON 0782561496/075666...
WAY To JOIN REAL ILLUMINATI AGENT IN KAMPALA UGANDA CALL ON 0782561496/075666...WAY To JOIN REAL ILLUMINATI AGENT IN KAMPALA UGANDA CALL ON 0782561496/075666...
WAY To JOIN REAL ILLUMINATI AGENT IN KAMPALA UGANDA CALL ON 0782561496/075666...
fikfameicailluminati
 
Audi Won’t Start Expert Battery Diagnosis and Starting System Repair Solutions
Audi Won’t Start Expert Battery Diagnosis and Starting System Repair SolutionsAudi Won’t Start Expert Battery Diagnosis and Starting System Repair Solutions
Audi Won’t Start Expert Battery Diagnosis and Starting System Repair Solutions
European Service Center
 
caterpillar 308E2 mini hyd excavator F8C servcie manual
caterpillar 308E2 mini hyd excavator F8C servcie manualcaterpillar 308E2 mini hyd excavator F8C servcie manual
caterpillar 308E2 mini hyd excavator F8C servcie manual
Heavy Equipment Manual
 
Electrical_System_Presentation.pptx_elec
Electrical_System_Presentation.pptx_elecElectrical_System_Presentation.pptx_elec
Electrical_System_Presentation.pptx_elec
kumares22061997
 
Caterpillar Cat 324E and 324E L Excavator (Prefix KTE) Service Repair Manual ...
Caterpillar Cat 324E and 324E L Excavator (Prefix KTE) Service Repair Manual ...Caterpillar Cat 324E and 324E L Excavator (Prefix KTE) Service Repair Manual ...
Caterpillar Cat 324E and 324E L Excavator (Prefix KTE) Service Repair Manual ...
chemozeng6118
 
Caterpillar Cat 320D2L Excavator (Prefix XCC) Service Repair Manual Instant D...
Caterpillar Cat 320D2L Excavator (Prefix XCC) Service Repair Manual Instant D...Caterpillar Cat 320D2L Excavator (Prefix XCC) Service Repair Manual Instant D...
Caterpillar Cat 320D2L Excavator (Prefix XCC) Service Repair Manual Instant D...
zou7975bihao
 
Top Driving Tips to Pass Your Driving Test with Confidence
Top Driving Tips to Pass Your Driving Test with ConfidenceTop Driving Tips to Pass Your Driving Test with Confidence
Top Driving Tips to Pass Your Driving Test with Confidence
Lucas Taylor
 
backlink automotice related - Sheet1.pdf
backlink automotice related  - Sheet1.pdfbacklink automotice related  - Sheet1.pdf
backlink automotice related - Sheet1.pdf
Drivestylish
 
BCG-Melbourne-as-a-Global-Cultural-Destination-Summary-for-CV-website-1.pptx
BCG-Melbourne-as-a-Global-Cultural-Destination-Summary-for-CV-website-1.pptxBCG-Melbourne-as-a-Global-Cultural-Destination-Summary-for-CV-website-1.pptx
BCG-Melbourne-as-a-Global-Cultural-Destination-Summary-for-CV-website-1.pptx
pairagents39
 
caterpillar 308E2 SR mini excavator TM2 service manual
caterpillar 308E2 SR mini excavator TM2 service manualcaterpillar 308E2 SR mini excavator TM2 service manual
caterpillar 308E2 SR mini excavator TM2 service manual
Heavy Equipment Manual
 
bcg book presentation with all slides proper
bcg book presentation with all slides  properbcg book presentation with all slides  proper
bcg book presentation with all slides proper
pairagents39
 
Caterpillar Cat 324E and 324E L Excavator (Prefix KTE) Service Repair Manual ...
Caterpillar Cat 324E and 324E L Excavator (Prefix KTE) Service Repair Manual ...Caterpillar Cat 324E and 324E L Excavator (Prefix KTE) Service Repair Manual ...
Caterpillar Cat 324E and 324E L Excavator (Prefix KTE) Service Repair Manual ...
chun79cuoyi
 
displayports types of cable and uses of ports IT WORKSHOP 2.pptx
displayports  types of cable and uses of ports IT WORKSHOP 2.pptxdisplayports  types of cable and uses of ports IT WORKSHOP 2.pptx
displayports types of cable and uses of ports IT WORKSHOP 2.pptx
yashwanthreddydaggul
 
Zipaworld: Redefining the Future of Air Freight Forwarding and Digital Logistics
Zipaworld: Redefining the Future of Air Freight Forwarding and Digital LogisticsZipaworld: Redefining the Future of Air Freight Forwarding and Digital Logistics
Zipaworld: Redefining the Future of Air Freight Forwarding and Digital Logistics
zipaworld innovation
 
Case IH Case International 5140 Tractor Service Repair Manual.pdf
Case IH Case International 5140 Tractor Service Repair Manual.pdfCase IH Case International 5140 Tractor Service Repair Manual.pdf
Case IH Case International 5140 Tractor Service Repair Manual.pdf
Service Repair Manual
 
Volvo a35e OperatorS Manual DOWNLOAD PDF
Volvo a35e OperatorS Manual DOWNLOAD PDFVolvo a35e OperatorS Manual DOWNLOAD PDF
Volvo a35e OperatorS Manual DOWNLOAD PDF
Service Repair Manual
 
SD200 Operator Manual PDF – Complete Guide for Operators.pdf
SD200 Operator Manual PDF – Complete Guide for Operators.pdfSD200 Operator Manual PDF – Complete Guide for Operators.pdf
SD200 Operator Manual PDF – Complete Guide for Operators.pdf
Service Repair Manual
 
SD160F Operator Manual PDF – Safety & Operation Guide Download.pdf
SD160F Operator Manual PDF – Safety & Operation Guide Download.pdfSD160F Operator Manual PDF – Safety & Operation Guide Download.pdf
SD160F Operator Manual PDF – Safety & Operation Guide Download.pdf
Service Repair Manual
 
Equipment Volvo EC480E Operator Manual.pdf
Equipment Volvo EC480E Operator Manual.pdfEquipment Volvo EC480E Operator Manual.pdf
Equipment Volvo EC480E Operator Manual.pdf
Service Repair Manual
 
SD190DX Operator Manual – Download User Instructions PDF.pdf
SD190DX Operator Manual – Download User Instructions PDF.pdfSD190DX Operator Manual – Download User Instructions PDF.pdf
SD190DX Operator Manual – Download User Instructions PDF.pdf
Service Repair Manual
 
WAY To JOIN REAL ILLUMINATI AGENT IN KAMPALA UGANDA CALL ON 0782561496/075666...
WAY To JOIN REAL ILLUMINATI AGENT IN KAMPALA UGANDA CALL ON 0782561496/075666...WAY To JOIN REAL ILLUMINATI AGENT IN KAMPALA UGANDA CALL ON 0782561496/075666...
WAY To JOIN REAL ILLUMINATI AGENT IN KAMPALA UGANDA CALL ON 0782561496/075666...
fikfameicailluminati
 
Audi Won’t Start Expert Battery Diagnosis and Starting System Repair Solutions
Audi Won’t Start Expert Battery Diagnosis and Starting System Repair SolutionsAudi Won’t Start Expert Battery Diagnosis and Starting System Repair Solutions
Audi Won’t Start Expert Battery Diagnosis and Starting System Repair Solutions
European Service Center
 
caterpillar 308E2 mini hyd excavator F8C servcie manual
caterpillar 308E2 mini hyd excavator F8C servcie manualcaterpillar 308E2 mini hyd excavator F8C servcie manual
caterpillar 308E2 mini hyd excavator F8C servcie manual
Heavy Equipment Manual
 
Electrical_System_Presentation.pptx_elec
Electrical_System_Presentation.pptx_elecElectrical_System_Presentation.pptx_elec
Electrical_System_Presentation.pptx_elec
kumares22061997
 
Caterpillar Cat 324E and 324E L Excavator (Prefix KTE) Service Repair Manual ...
Caterpillar Cat 324E and 324E L Excavator (Prefix KTE) Service Repair Manual ...Caterpillar Cat 324E and 324E L Excavator (Prefix KTE) Service Repair Manual ...
Caterpillar Cat 324E and 324E L Excavator (Prefix KTE) Service Repair Manual ...
chemozeng6118
 
Caterpillar Cat 320D2L Excavator (Prefix XCC) Service Repair Manual Instant D...
Caterpillar Cat 320D2L Excavator (Prefix XCC) Service Repair Manual Instant D...Caterpillar Cat 320D2L Excavator (Prefix XCC) Service Repair Manual Instant D...
Caterpillar Cat 320D2L Excavator (Prefix XCC) Service Repair Manual Instant D...
zou7975bihao
 
Top Driving Tips to Pass Your Driving Test with Confidence
Top Driving Tips to Pass Your Driving Test with ConfidenceTop Driving Tips to Pass Your Driving Test with Confidence
Top Driving Tips to Pass Your Driving Test with Confidence
Lucas Taylor
 
backlink automotice related - Sheet1.pdf
backlink automotice related  - Sheet1.pdfbacklink automotice related  - Sheet1.pdf
backlink automotice related - Sheet1.pdf
Drivestylish
 
BCG-Melbourne-as-a-Global-Cultural-Destination-Summary-for-CV-website-1.pptx
BCG-Melbourne-as-a-Global-Cultural-Destination-Summary-for-CV-website-1.pptxBCG-Melbourne-as-a-Global-Cultural-Destination-Summary-for-CV-website-1.pptx
BCG-Melbourne-as-a-Global-Cultural-Destination-Summary-for-CV-website-1.pptx
pairagents39
 
caterpillar 308E2 SR mini excavator TM2 service manual
caterpillar 308E2 SR mini excavator TM2 service manualcaterpillar 308E2 SR mini excavator TM2 service manual
caterpillar 308E2 SR mini excavator TM2 service manual
Heavy Equipment Manual
 
bcg book presentation with all slides proper
bcg book presentation with all slides  properbcg book presentation with all slides  proper
bcg book presentation with all slides proper
pairagents39
 
Caterpillar Cat 324E and 324E L Excavator (Prefix KTE) Service Repair Manual ...
Caterpillar Cat 324E and 324E L Excavator (Prefix KTE) Service Repair Manual ...Caterpillar Cat 324E and 324E L Excavator (Prefix KTE) Service Repair Manual ...
Caterpillar Cat 324E and 324E L Excavator (Prefix KTE) Service Repair Manual ...
chun79cuoyi
 
displayports types of cable and uses of ports IT WORKSHOP 2.pptx
displayports  types of cable and uses of ports IT WORKSHOP 2.pptxdisplayports  types of cable and uses of ports IT WORKSHOP 2.pptx
displayports types of cable and uses of ports IT WORKSHOP 2.pptx
yashwanthreddydaggul
 
Zipaworld: Redefining the Future of Air Freight Forwarding and Digital Logistics
Zipaworld: Redefining the Future of Air Freight Forwarding and Digital LogisticsZipaworld: Redefining the Future of Air Freight Forwarding and Digital Logistics
Zipaworld: Redefining the Future of Air Freight Forwarding and Digital Logistics
zipaworld innovation
 
Case IH Case International 5140 Tractor Service Repair Manual.pdf
Case IH Case International 5140 Tractor Service Repair Manual.pdfCase IH Case International 5140 Tractor Service Repair Manual.pdf
Case IH Case International 5140 Tractor Service Repair Manual.pdf
Service Repair Manual
 
Volvo a35e OperatorS Manual DOWNLOAD PDF
Volvo a35e OperatorS Manual DOWNLOAD PDFVolvo a35e OperatorS Manual DOWNLOAD PDF
Volvo a35e OperatorS Manual DOWNLOAD PDF
Service Repair Manual
 
SD200 Operator Manual PDF – Complete Guide for Operators.pdf
SD200 Operator Manual PDF – Complete Guide for Operators.pdfSD200 Operator Manual PDF – Complete Guide for Operators.pdf
SD200 Operator Manual PDF – Complete Guide for Operators.pdf
Service Repair Manual
 
Ad

PHP PPT.pptxPHP PPT.pptxPHP PPT.pptxPHP n

  • 1. PHP (BASICS) • PHP Defination • PHP Syntax • PHP Comments • PHPVariables • ECHO and PRINT • PHP Datatypes • PHP Constents • PHP Operators
  • 2. P H P • PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. What is PHP? • PHP is an acronym for "PHP: Hypertext Preprocessor" • PHP is a widely-used, open source scripting language • PHP scripts are executed on the server • PHP is free to download and use What is a PHP File? • PHP files have extension ".php"
  • 3. WHAT CAN PHP DO? • PHP can generate dynamic page content • PHP can create, open, read, write, delete, and close files on the server • PHP can collect form data • PHP can send and receive cookies • PHP can add, delete, modify data in your database • PHP can be used to control user-access • PHP can encrypt data
  • 4. P H P S Y N T A X P H P C O M M E N T S <html> <body> <h1>My first PHP page</h1> <?php echo "Hello World!"; ?> </body> </html> // Outputs a welcome message: echo "Welcome Home!"; Multi-line Comments Multi-line comments start with /* and end with */. Any text between /* and */ will be ignored.
  • 5. 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 • Variable names are case-sensitive Example- $x = 5; $y = "John"
  • 6. P H P VA R I A B L E S S C O P E The scope of a variable is the part of the script where the variable can be referenced/used. PHP has three different variable scopes: • local • global • static
  • 7. GLOBAL AND LOCAL SCOPE • A variable declared outside a function has a GLOBAL SCOPE and can only be accessed outside a function. Global Scope <?php $x = 5; // global scope function myTest() { // using x inside this function will generate an error echo "<p>Variable x inside function is: $x</p>"; } myTest(); echo "<p>Variable x outside function is: $x</p>"; ?> Output - Variable x inside function is: Variable x outside function is: 5
  • 8. LOCAL SCOPE <?php function myTest() { $x = 5; // local scope echo "<p>Variable x inside function is: $x</p>"; } myTest(); // using x outside the function will generate an error echo "<p>Variable x outside function is: $x</p>"; ?> Output - Variable x inside function is: 5 Variable x outside function is:
  • 9. P H P E C H O A N D P R I N T S T A T E M E N T S 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.
  • 10. P H P D A T A T Y P E S 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 • NULL
  • 11. P H P S T R I N G A string is a sequence of characters, like "Hello world!“. <?php $x = "Hello world!"; $y = 'Hello world!'; var_dump($x); echo "<br>"; var_dump($y); ?> Output - string(12) "Hello world!" string(12) "Hello world!"
  • 12. P H P I N T E G E R • An integer must have at least one digit • An integer must not have a decimal point • An integer can be either positive or negative • Integers can be specified in: decimal (base 10), hexadecimal (base 16), octal (base 8), or binary (base 2) notation <?php $x = 5985; var_dump($x); ?> Output - int(5985)
  • 13. PHP FLOAT • A float (floating point number) is a number with a decimal point or a number in exponential form. • In the following example $x is a float.The PHP var_dump() function returns the data type and value: <?php $x = 10.365; var_dump($x); ?> Output - float(10.365)
  • 14. PHP BOOLEAN A Boolean represents two possible states:TRUE or FALSE. <html> <body> <?php $x = true; var_dump($x); ?> </body> </html> Output - bool(true)
  • 15. P H P A R R A Y • An array stores multiple values in one single variable. • In the following example $cars is an array.The PHP var_dump() function returns the data type and value: <?php $cars = array("BMW","Toyota"); var_dump($cars); ?> Output – array(2) { [0]=> string(3) "BMW" [1]=> string(6) "Toyota" }
  • 16. P H P C A S T I N G Change DataType Casting in PHP is done with these statements: (string) - Converts to data type String (int) - Converts to data type Integer (float) - Converts to data type Float (bool) - Converts to data type Boolean (array) - Converts to data type Array (object) - Converts to data type Object (unset) - Converts to data type NULL
  • 17. <?php $a="first step"; $b="2"; $c="true"; $d="3.89"; $f="null"; $a= (string) $a; $b= (array) $b; $c= (bool) $c; $d= (float) $d; $f= (string) $f; //To verify the type of any object in PHP, use the var_dump() funtion: var_du($a); echo"<br>"; var_dump($b); echo"<br>"; var_dump($c); echo"<br>"; var_dump($d); echo"<br>"; var_dump($f); ?> OUTPUT : string(10) "first step" array(1) { [0]=> string(1) "2" } bool(true) float(3.89) string(4) "null"
  • 18. P H P C O N S T A N T S • Constants are like variables, except that once they are defined they cannot be changed or undefined. • 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) Syntax: define(name, value, case-insensitive);
  • 19. P H P O P E R ATO R S 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 • Conditional assignment operators
  • 20. PHP ARITHMETIC OPERATORS The PHP arithmetic operators are used with numeric values to perform common arithmetical operations, such as addition, subtraction, multiplication etc. 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
  • 21. P H P A S S I G N M E N T O P E R AT O R S The PHP assignment operators are used with numeric values to write a value to a variable 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
  • 22. P H P C O M PA R I S O N O P E R ATO R S The PHP comparison operators are used to compare two values (number or string): Operator Name Example Result == Equal $x == $y Returns true if $x is equal to $y === Identical $x === $y Returns true if $x is equal to $y, and they are of the same type != Not equal $x != $y Returns true if $x is not equal to $y <> Not equal $x <> $y Returns true if $x is not equal to $y !== Not identical $x !== $y Returns true if $x is not equal to $y, or they are not of the same type > Greater than $x > $y Returns true if $x is greater than $y < Less than $x < $y Returns true if $x is less than $y >= Greater than or equal to $x >= $y Returns true if $x is greater than or equal to $y <= Less than or equal to $x <= $y Returns true if $x is less than or equal to $y <=> Spaceship $x <=> $y Returns an integer less than, equal to, or greater than zero, depending on if $x is less than, equal to, or greater than $y. Introduced in PHP 7.
  • 23. PH P IN CR E ME N T / D E CRE M EN T O PE R ATOR S 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 Same as... 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
  • 24. P H P L O G I C A L O P E R AT O R S The PHP logical operators are used to combine conditional statements. Operator Name Example Result and And $x and $y True if both $x and $y are true or Or $x or $y True if either $x or $y is true xor Xor $x xor $y True if either $x or $y is true, but not both && And $x && $y True if both $x and $y are true || Or $x || $y True if either $x or $y is true ! Not !$x True if $x is not true
  • 25. P H P S T R I N G O P E R AT O R S PHP has two operators that are specially designed for strings. Operator Name Example Result . Concatenation $txt1 . $txt2 Concatenation of $txt1 and $txt2 .= Concatenation assignment $txt1 .= $txt2 Appends $txt2 to $txt1
  • 26. P H P A R R AY O P E R ATO R S The PHP array operators are used to compare arrays. Operator Name Example Result + Union $x + $y Union of $x and $y == Equality $x == $y Returns true if $x and $y have the same key/value pairs === Identity $x === $y Returns true if $x and $y have the same key/value pairs in the same order and of the same types != Inequality $x != $y Returns true if $x is not equal to $y <> Inequality $x <> $y Returns true if $x is not equal to $y !== Non-identity $x !== $y Returns true if $x is not identical to $y
  • 27. P H P C O N D I T I O N A L A S S I G N M E N T O P E R ATO R S The PHP conditional assignment operators are used to set a value depending on conditions: Operator Name Example Result ?: Ternary $x = expr1 ? expr2 : e xpr3 Returns the value of $x. The value of $x is expr2 if expr1 = TRUE. The value of $x is expr3 if expr1 = FALSE ?? Null coalescing $x = expr1 ?? expr2 Returns the value of $x. The value of $x is expr1 if expr1 exists, and is not NULL. If expr1 does not exist, or is NULL, the value of $x is expr2.
  • 28. PHP IF STATEMENTS if statement - executes some code if one condition is true. <?php if (5 > 3) { echo "Have a good day!"; } ?> Output - Have a good day!
  • 29. P H P I F. . . E L S E S TAT E M E N T S The if...else statement executes some code if a condition is true and another code if that condition is false. <?php $t = date("H"); if ($t < "20") { echo "Have a good day!"; } else { echo "Have a good night!"; } ?> Output - Have a good day!
  • 30. I F. . . E LS E I F. . . E LS E S TAT E ME NT The if...elseif...else statement executes different codes for more than two conditions. <?php if ($t < "10") { echo "Have a good morning!"; } elseif ($t < "20") { echo "Have a good day!"; } else { echo "Have a good night!"; } ?> Output - Have a good day!