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

PHP - Introduction to File Handling with PHP
PHP -  Introduction to  File Handling with PHPPHP -  Introduction to  File Handling with PHP
PHP - Introduction to File Handling with PHP
Vibrant Technologies & Computers
 
PHP
PHPPHP
Files in php
Files in phpFiles in php
Files in php
sana mateen
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
Zeeshan Ahmed
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
Kengatharaiyer Sarveswaran
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
Vineet Kumar Saini
 
Chapter 02 php basic syntax
Chapter 02   php basic syntaxChapter 02   php basic syntax
Chapter 02 php basic syntax
Dhani Ahmad
 
PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array. PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array.
wahidullah mudaser
 
4.2 PHP Function
4.2 PHP Function4.2 PHP Function
4.2 PHP Function
Jalpesh Vasa
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
Nidhi mishra
 
JavaScript - Chapter 5 - Operators
 JavaScript - Chapter 5 - Operators JavaScript - Chapter 5 - Operators
JavaScript - Chapter 5 - Operators
WebStackAcademy
 
Php string function
Php string function Php string function
Php string function
Ravi Bhadauria
 
PHP Workshop Notes
PHP Workshop NotesPHP Workshop Notes
PHP Workshop Notes
Pamela Fox
 
Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
Priya Goyal
 
XML DTD and Schema
XML DTD and SchemaXML DTD and Schema
XML DTD and Schema
hamsa nandhini
 
Php technical presentation
Php technical presentationPhp technical presentation
Php technical presentation
dharmendra kumar dhakar
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
WebStackAcademy
 

What's hot (20)

PHP - Introduction to File Handling with PHP
PHP -  Introduction to  File Handling with PHPPHP -  Introduction to  File Handling with PHP
PHP - Introduction to File Handling with PHP
 
PHP
PHPPHP
PHP
 
Files in php
Files in phpFiles in php
Files in php
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 
Chapter 02 php basic syntax
Chapter 02   php basic syntaxChapter 02   php basic syntax
Chapter 02 php basic syntax
 
PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array. PHP Arrays - indexed and associative array.
PHP Arrays - indexed and associative array.
 
Html frames
Html framesHtml frames
Html frames
 
4.2 PHP Function
4.2 PHP Function4.2 PHP Function
4.2 PHP Function
 
Php basics
Php basicsPhp basics
Php basics
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
JavaScript - Chapter 5 - Operators
 JavaScript - Chapter 5 - Operators JavaScript - Chapter 5 - Operators
JavaScript - Chapter 5 - Operators
 
Php string function
Php string function Php string function
Php string function
 
Lesson 5 php operators
Lesson 5   php operatorsLesson 5   php operators
Lesson 5 php operators
 
PHP Workshop Notes
PHP Workshop NotesPHP Workshop Notes
PHP Workshop Notes
 
Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
 
XML DTD and Schema
XML DTD and SchemaXML DTD and Schema
XML DTD and Schema
 
Php technical presentation
Php technical presentationPhp technical presentation
Php technical presentation
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
 

Similar to php basics

Materi Dasar PHP
Materi Dasar PHPMateri Dasar PHP
Materi Dasar PHP
Robby Firmansyah
 
Introduction to php contains basic....pptx
Introduction to php contains basic....pptxIntroduction to php contains basic....pptx
Introduction to php contains basic....pptx
RanjithaGowda63
 
Hsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdfHsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdf
AAFREEN SHAIKH
 
Introduction to PHP_Slides by Lesley_Bonyo.pdf
Introduction to PHP_Slides by Lesley_Bonyo.pdfIntroduction to PHP_Slides by Lesley_Bonyo.pdf
Introduction to PHP_Slides by Lesley_Bonyo.pdf
MacSila
 
php Chapter 1.pptx
php Chapter 1.pptxphp Chapter 1.pptx
php Chapter 1.pptx
HambaAbebe2
 
Php(report)
Php(report)Php(report)
Php(report)Yhannah
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
pratik tambekar
 
Php1
Php1Php1
Server Scripting Language -PHP
Server Scripting Language -PHPServer Scripting Language -PHP
Server Scripting Language -PHP
Deo Shao
 
Basic of PHP
Basic of PHPBasic of PHP
Basic of PHP
Nisa Soomro
 
PHP MATERIAL
PHP MATERIALPHP MATERIAL
PHP MATERIAL
zatax
 
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...
anshkhurana01
 
Php unit i
Php unit iPhp unit i
Php unit i
BagavathiLakshmi
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Muhamad Al Imran
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Muhamad Al Imran
 

Similar to php basics (20)

Materi Dasar PHP
Materi Dasar PHPMateri Dasar PHP
Materi Dasar PHP
 
Php Basics
Php BasicsPhp Basics
Php Basics
 
Introduction to php contains basic....pptx
Introduction to php contains basic....pptxIntroduction to php contains basic....pptx
Introduction to php contains basic....pptx
 
Hsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdfHsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdf
 
Introduction to PHP_Slides by Lesley_Bonyo.pdf
Introduction to PHP_Slides by Lesley_Bonyo.pdfIntroduction to PHP_Slides by Lesley_Bonyo.pdf
Introduction to PHP_Slides by Lesley_Bonyo.pdf
 
Php
PhpPhp
Php
 
php Chapter 1.pptx
php Chapter 1.pptxphp Chapter 1.pptx
php Chapter 1.pptx
 
PHP
PHPPHP
PHP
 
Php essentials
Php essentialsPhp essentials
Php essentials
 
Php(report)
Php(report)Php(report)
Php(report)
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Php1
Php1Php1
Php1
 
Server Scripting Language -PHP
Server Scripting Language -PHPServer Scripting Language -PHP
Server Scripting Language -PHP
 
Basic of PHP
Basic of PHPBasic of PHP
Basic of PHP
 
PHP MATERIAL
PHP MATERIALPHP MATERIAL
PHP MATERIAL
 
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 unit i
Php unit iPhp unit i
Php unit i
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
 

Recently uploaded

The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 

Recently uploaded (20)

The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 

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); ?>