SlideShare a Scribd company logo
Presentation on PHP Basics
Submitted to:
Navjot sir
Submitted by:
Ms. Anmol Rattan
1811591
MCA 5th Semester
Outlines
PHP Basic Syntax
Case Sensitivity in PHP
PHP Printing function
Declaration of variables
Loops in PHP
Functions in PHP
1. This is most commonly used and recommended
form is:
PHP Basic Syntax
<?PHP
PHP CODE GOES IN HERE
?>
2. This is another way to add PHP script(HTML
or Script style tags)
Syntax:-
<script language=“PHP”>
PHP CODE GOES IN HERE
</script>
3. This is called “Short” tags.
i. Syntax:
<?
PHP CODE GOES
HERE
?>
ii. Syntax:
<%
PHP CODE GOES
HERE
%>
Embedding of PHP within HTML
<html>
<body>
<?
// php code goes here
?>
</body>
</html>
Case Sensitivity in PHP
In PHP, Variable names are case-sensitive but
function names are not case sensitive.
• If you defined variable in lowercase, then you
need to use it in lowercase everywhere in
program. If we define a
variable $name = "James"; $NAME will not
work
• If you defined function name in lowercase, but
calling them in uppercase it will work. For
example, If we define function sum() {} then
calling SUM() will also work.
Case sensitive (both
user defined and PHP
defined)
• variables
• constants
• array keys
• class properties
• class constants
• Strings
Case insensitive (both
user defined and PHP
defined)
• Functions Name
• class constructors
• class methods
• Class Names
• keywords and
constructs (if, else,
null, foreach, echo
etc.)
PHP PRINTING FUNCTION
1. print() – The print() is used to create PHP print
statement to print given data to the browser. It is
a PHP language construct and not a function. So,
we can use ‘print’ without parenthesis for
creating a print statement.
Example:
<?PHP
print "Anmol";
//(or)
print("Anmol");
?>
OUTPUT
AnmolAnmol
PHP Echo statement
• It is a construct as like as print(). The difference
is that the echo() will accept multiple data
separated by commas.
• PHP echo statement can be used to print string,
multi line strings, variables, array etc.
EXAMPLE:
ECHO "APPLE","GRAPES“ //INVALID
ECHO ("APPLE","GRAPES"); //VALID
Example:
echo "Apple";
echo("Apple");
Declaration of variables in PHP
• A variable in PHP is a name of memory location
that holds data. A variable is used to store data
temporarily.
• In PHP, a variable is declared using $ sign
followed by variable name .
Syntax :-
$variablename=value;
Rules for declaring a variable in
PHP
• The variables in PHP are started by the dollar
sign($).
• PHP variables must start with letter or underscore
only.
• PHP variable can't be start with numbers and
special symbols.
• The variables names are case sensitive i.e.
$kushal and $KUSHAL are two different
variables for interpreter.
PHP Variable: Declaring string,
integer and float
OUTPUT
string is: hello string
integer is: 200
float is: 44.6
<?php
$str="hello string";
$x=200;
$y=44.6;
echo "string is: $str <br/>";
echo "integer is: $x <br/>";
echo "float is: $y <br/>";
?>
Loops in PHP
• When we want to execute same code
multiple times then we can put it into a loop block
to avoid code repetition. Loop structure includes
three sections. These are,
•Initialization
•Conditional execution
•Incrementation / decrementation
PHP support four different types of
looping control statements:
1. While Loop
2. Do…While Loop
3. For Loop
4. Foreach Loop
1. While Loop
• while loop is also known a entry control loop.
• In this loop, every time condition is checked and
if condition is true, then block of while loop is
executed.
• Loop will terminate if condition will become
false.
Syntax:
while(condition)
{
code to execute;
}
2. Do…While loop
• It is also known as exit controlled loop as in this
condition is checked after executing the block of
loop.
• Do while loop executes a block of code at least
once .
Syntax:
do
{
//codes
}
while(condition);
3. For Loop
• The for loop is more fast than while loop and do
while loop.
• It has the initialization, conditional statement and
increments/decrements in a single line.
Syntax:
for(intialization;
condiion;incr/decr)
{
//Body of loop;
}
• foreach looping structure is used to iterate through
each element of an array starting from first
element.
• It will depend upon the number of elements of
array that how much time the loop will execute.
• Foreach loop works only on arrays.
4. foreach loop
Example
<?php
$Myarray=array('anmol‘ ,
'rohit‘ ,‘ lokesh');
foreach($Myarray as $value)
{
echo $value."<br>";
}
?>
Output:-
anmol
rohit
lokesh
Functions in PHP
• PHP function is a block of statements that can
be reused number of times in PHP script.
• A function can take argument and can return
value.
Syntax:
function functionName()
{
Code to be executed;
}
Advantages of PHP Functions
• Code Reusability: PHP functions are defined
only once and can be invoked many times.
• Less Code: It saves a lot of code because By the
use of function, you can write the logic only once
and reuse it.
• Easy to understand: it is easier to understand the
flow of the application because every logic is
divided in the form of functions.
PHP Functions Example
Output
Hello PHP
<?php
function sayHello()
{
echo "Hello PHP";
}
sayHello();//calling function
?>
PHP functions with arguments
Output
Hello Sonoo
Hello Vimal
Hello John
<?php
function sayHello($name)
{
echo "Hello $name<br/>";
}
sayHello("Sonoo");
sayHello("Vimal");
sayHello("John");
?>
Function with return value
Output
sum of 2 and 5 is: 7
<?php
function sum($a, $b){
$c=$a+$b;
return $c;
}
$a=2;$b=5;
echo "sum of $a and $b is:
".sum($a,$b);
?>
php basics

More Related Content

What's hot (20)

PPTX
Lesson 1 php syntax
MLG College of Learning, Inc
 
PDF
JAVA PROGRAMMING - The Collections Framework
Jyothishmathi Institute of Technology and Science Karimnagar
 
PPT
Cookies & Session
university of education,Lahore
 
DOCX
Php forms and validations by naveen kumar veligeti
Naveen Kumar Veligeti
 
PPT
PHP - Introduction to PHP AJAX
Vibrant Technologies & Computers
 
PPTX
Java web application development
RitikRathaur
 
PPT
Php with MYSQL Database
Computer Hardware & Trouble shooting
 
PPTX
Php
Shyam Khant
 
PPTX
Introduction to php
Taha Malampatti
 
PPT
Cookies and sessions
Lena Petsenchuk
 
PPTX
Classes, objects in JAVA
Abhilash Nair
 
PDF
Php Tutorials for Beginners
Vineet Kumar Saini
 
PPT
Java Networking
Sunil OS
 
PPT
Introduction to Web Programming - first course
Vlad Posea
 
PPT
Introduction to PHP
Jussi Pohjolainen
 
PPT
Introduction to BOOTSTRAP
Jeanie Arnoco
 
PPTX
Polymorphism in java
Elizabeth alexander
 
PDF
Php introduction
krishnapriya Tadepalli
 
PPTX
Statements and Conditions in PHP
Maruf Abdullah (Rion)
 
Lesson 1 php syntax
MLG College of Learning, Inc
 
JAVA PROGRAMMING - The Collections Framework
Jyothishmathi Institute of Technology and Science Karimnagar
 
Php forms and validations by naveen kumar veligeti
Naveen Kumar Veligeti
 
PHP - Introduction to PHP AJAX
Vibrant Technologies & Computers
 
Java web application development
RitikRathaur
 
Php with MYSQL Database
Computer Hardware & Trouble shooting
 
Introduction to php
Taha Malampatti
 
Cookies and sessions
Lena Petsenchuk
 
Classes, objects in JAVA
Abhilash Nair
 
Php Tutorials for Beginners
Vineet Kumar Saini
 
Java Networking
Sunil OS
 
Introduction to Web Programming - first course
Vlad Posea
 
Introduction to PHP
Jussi Pohjolainen
 
Introduction to BOOTSTRAP
Jeanie Arnoco
 
Polymorphism in java
Elizabeth alexander
 
Php introduction
krishnapriya Tadepalli
 
Statements and Conditions in PHP
Maruf Abdullah (Rion)
 

Similar to php basics (20)

PPTX
Php by shivitomer
Shivi Tomer
 
PPTX
Php.ppt
Nidhi mishra
 
PDF
php AND MYSQL _ppt.pdf
SVN Polytechnic Kalan Sultanpur UP
 
PPT
PHP - Introduction to PHP - Mazenet Solution
Mazenetsolution
 
PPTX
Php intro by sami kz
sami2244
 
PDF
Hsc IT 5. Server-Side Scripting (PHP).pdf
AAFREEN SHAIKH
 
PPTX
Php1
Shamik Tiwari
 
PPTX
PHPneweeeeeeeeeeeeeeeeeeeeeeeeeeeeee.pptx
kamalsmail1
 
PPT
PHP - Web Development
Niladri Karmakar
 
PDF
WT_PHP_PART1.pdf
HambardeAtharva
 
PPT
introduction to php web programming 2024.ppt
idaaryanie
 
PPTX
Introduction in php part 2
Bozhidar Boshnakov
 
PPTX
Php Unit 1
team11vgnt
 
PDF
Introduction to PHP_Slides by Lesley_Bonyo.pdf
MacSila
 
PPTX
INTRODUCTION ON PHP - SERVER SIDE SCRIPTING LANGUAGE
PRIYADARSINIK3
 
PPT
PHP - DataType,Variable,Constant,Operators,Array,Include and require
TheCreativedev Blog
 
PPTX
PHP Lecture 01 .pptx PHP Lecture 01 pptx
shahgohar1
 
PPT
Php(report)
Yhannah
 
PPTX
The basics of php for engeneering students
rahuljustin77
 
Php by shivitomer
Shivi Tomer
 
Php.ppt
Nidhi mishra
 
php AND MYSQL _ppt.pdf
SVN Polytechnic Kalan Sultanpur UP
 
PHP - Introduction to PHP - Mazenet Solution
Mazenetsolution
 
Php intro by sami kz
sami2244
 
Hsc IT 5. Server-Side Scripting (PHP).pdf
AAFREEN SHAIKH
 
PHPneweeeeeeeeeeeeeeeeeeeeeeeeeeeeee.pptx
kamalsmail1
 
PHP - Web Development
Niladri Karmakar
 
WT_PHP_PART1.pdf
HambardeAtharva
 
introduction to php web programming 2024.ppt
idaaryanie
 
Introduction in php part 2
Bozhidar Boshnakov
 
Php Unit 1
team11vgnt
 
Introduction to PHP_Slides by Lesley_Bonyo.pdf
MacSila
 
INTRODUCTION ON PHP - SERVER SIDE SCRIPTING LANGUAGE
PRIYADARSINIK3
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
TheCreativedev Blog
 
PHP Lecture 01 .pptx PHP Lecture 01 pptx
shahgohar1
 
Php(report)
Yhannah
 
The basics of php for engeneering students
rahuljustin77
 
Ad

Recently uploaded (20)

PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
Ad

php basics

  • 1. Presentation on PHP Basics Submitted to: Navjot sir Submitted by: Ms. Anmol Rattan 1811591 MCA 5th Semester
  • 2. Outlines PHP Basic Syntax Case Sensitivity in PHP PHP Printing function Declaration of variables Loops in PHP Functions in PHP
  • 3. 1. This is most commonly used and recommended form is: PHP Basic Syntax <?PHP PHP CODE GOES IN HERE ?>
  • 4. 2. This is another way to add PHP script(HTML or Script style tags) Syntax:- <script language=“PHP”> PHP CODE GOES IN HERE </script>
  • 5. 3. This is called “Short” tags. i. Syntax: <? PHP CODE GOES HERE ?> ii. Syntax: <% PHP CODE GOES HERE %>
  • 6. Embedding of PHP within HTML <html> <body> <? // php code goes here ?> </body> </html>
  • 7. Case Sensitivity in PHP In PHP, Variable names are case-sensitive but function names are not case sensitive. • If you defined variable in lowercase, then you need to use it in lowercase everywhere in program. If we define a variable $name = "James"; $NAME will not work • If you defined function name in lowercase, but calling them in uppercase it will work. For example, If we define function sum() {} then calling SUM() will also work.
  • 8. Case sensitive (both user defined and PHP defined) • variables • constants • array keys • class properties • class constants • Strings Case insensitive (both user defined and PHP defined) • Functions Name • class constructors • class methods • Class Names • keywords and constructs (if, else, null, foreach, echo etc.)
  • 9. PHP PRINTING FUNCTION 1. print() – The print() is used to create PHP print statement to print given data to the browser. It is a PHP language construct and not a function. So, we can use ‘print’ without parenthesis for creating a print statement.
  • 11. PHP Echo statement • It is a construct as like as print(). The difference is that the echo() will accept multiple data separated by commas. • PHP echo statement can be used to print string, multi line strings, variables, array etc.
  • 12. EXAMPLE: ECHO "APPLE","GRAPES“ //INVALID ECHO ("APPLE","GRAPES"); //VALID Example: echo "Apple"; echo("Apple");
  • 13. Declaration of variables in PHP • A variable in PHP is a name of memory location that holds data. A variable is used to store data temporarily. • In PHP, a variable is declared using $ sign followed by variable name . Syntax :- $variablename=value;
  • 14. Rules for declaring a variable in PHP • The variables in PHP are started by the dollar sign($). • PHP variables must start with letter or underscore only. • PHP variable can't be start with numbers and special symbols. • The variables names are case sensitive i.e. $kushal and $KUSHAL are two different variables for interpreter.
  • 15. PHP Variable: Declaring string, integer and float OUTPUT string is: hello string integer is: 200 float is: 44.6 <?php $str="hello string"; $x=200; $y=44.6; echo "string is: $str <br/>"; echo "integer is: $x <br/>"; echo "float is: $y <br/>"; ?>
  • 16. Loops in PHP • When we want to execute same code multiple times then we can put it into a loop block to avoid code repetition. Loop structure includes three sections. These are, •Initialization •Conditional execution •Incrementation / decrementation
  • 17. PHP support four different types of looping control statements: 1. While Loop 2. Do…While Loop 3. For Loop 4. Foreach Loop
  • 18. 1. While Loop • while loop is also known a entry control loop. • In this loop, every time condition is checked and if condition is true, then block of while loop is executed. • Loop will terminate if condition will become false.
  • 20. 2. Do…While loop • It is also known as exit controlled loop as in this condition is checked after executing the block of loop. • Do while loop executes a block of code at least once .
  • 22. 3. For Loop • The for loop is more fast than while loop and do while loop. • It has the initialization, conditional statement and increments/decrements in a single line.
  • 24. • foreach looping structure is used to iterate through each element of an array starting from first element. • It will depend upon the number of elements of array that how much time the loop will execute. • Foreach loop works only on arrays. 4. foreach loop
  • 25. Example <?php $Myarray=array('anmol‘ , 'rohit‘ ,‘ lokesh'); foreach($Myarray as $value) { echo $value."<br>"; } ?> Output:- anmol rohit lokesh
  • 26. Functions in PHP • PHP function is a block of statements that can be reused number of times in PHP script. • A function can take argument and can return value. Syntax: function functionName() { Code to be executed; }
  • 27. Advantages of PHP Functions • Code Reusability: PHP functions are defined only once and can be invoked many times. • Less Code: It saves a lot of code because By the use of function, you can write the logic only once and reuse it. • Easy to understand: it is easier to understand the flow of the application because every logic is divided in the form of functions.
  • 28. PHP Functions Example Output Hello PHP <?php function sayHello() { echo "Hello PHP"; } sayHello();//calling function ?>
  • 29. PHP functions with arguments Output Hello Sonoo Hello Vimal Hello John <?php function sayHello($name) { echo "Hello $name<br/>"; } sayHello("Sonoo"); sayHello("Vimal"); sayHello("John"); ?>
  • 30. Function with return value Output sum of 2 and 5 is: 7 <?php function sum($a, $b){ $c=$a+$b; return $c; } $a=2;$b=5; echo "sum of $a and $b is: ".sum($a,$b); ?>