SlideShare a Scribd company logo
1 of 45
12 Marks
 Rasmus Lerdoff developed PHP in1994 and Released 1998.
 PHP is a recursive acronym of Hypertext Pre-Processor.
 In 1998 PHP3 was released
 In 2000 PHP4 –improved speed and reliability
 In 2004 PHP5 –Improved support for Object-Oriented Programming
 In 2006 PHP5.2 was released
 In 2009 PHP5.3 –Namespace Support
 In 2012 PHP5.4-Improved with Performance and memory Requirement.
 In 2013 PHP5.5-With Generators and finally blocks for exception
handling
 In 2014 PHP5.6-constatnt expression, character encoding etc.
 In 2015 PHP7.0-Return type Declaration, spaceship operator etc.
 In 2016 PHP7.1 –nullable types
 In 2017 PHP7.2- Abstract method overriding
 In 2018 PHP 7.3
 Latest version of PHP is PHP7.4 released in 2019 offers to build
applications that influence s everything form the website
 PHP is a Server-side Scripting Language and used to create dynamic web
pages.
 Speed
 Easy to Use/Simplicity
 Stable
 Platform Independent/Portability
 Open Source
 Built-in Database Connection Module
 Powerful Library Support
 Flexibility
 Database Connectivity
 Speed-UP Custom Web Application
Development
 PHP Script is executed on the server,and the
plain HTML result is sent back to the browser.
 PHP Script can be placed anywhere in the
document .
 PHP script starts with <?php And ends with
?>
<?php
//PHP Code goes here
?>
 <?php
 echo “hello world!”
 ?>
 Step 1 : Download the XAMPP Server From
internet
 Step 2: Install XAMPP Software
 Step 3: Open and Click on the start button
that is in front of Apache Text
 Step 4: Create PHP file in htdocs directory
which is resides in XAMPP
directory[c:sampphtdocs].
 Step 5:Save Program with extension .php in
htdocs direcory , then open your browser and
then type http://localhost/programname.php
on address bar and press Enter key.
 Variable:In PHP, a variable is declared using a $
sign followed by the variable name. Here, some
important points to know about variables:
 As PHP is a loosely typed language, so we do not
need to declare the data types of the variables. It
automatically analyzes the values and makes
conversions to its correct datatype.
 After declaring a variable, it can be reused
throughout the code.
 Assignment Operator (=) is used to assign the
value to a variable.
 A variable must start with a dollar ($) sign,
followed by the variable name.
 It can only contain alpha-numeric character and
underscore (A-z, 0-9, _).
 A variable name must start with a letter or
underscore (_) character.
 A PHP variable name cannot contain spaces.
 One thing to be kept in mind that the variable
name cannot start with a number or special
symbols.
 PHP variables are case-sensitive, so $name and
$NAME both are treated as different variable.
 Data Type:
In PHP is_int() or is_integer() are used to test whether a
value is an integer
For example,
<?php
$a=10;
if(is_int($a))
{
echo "is an integer";
}
?>
In PHP is_float() is used to test whether a value is a
floating point number
<?php
$a=10.91;
if(is_float($a))
{
echo "is an floating point number";
}
?>
In PHP is_string() is used to test whether a value is a
String
For example 1,
<?php
$a="good";
if(is_string($a))
{
echo "is an string";
}
?>
For example 2,
<?php
$a="Good";
echo "$a morning";
?>
 <?php
 $a=true;
 if(is_bool($a))
 {
 echo "is an boolean";
 }
 ?>
 Numeric array − An array with a numeric index.
Values are stored and accessed in linear fashion.
 Associative array − An array with strings as index.
This stores element values in association with key
values rather than in a strict linear index order.
 Multidimensional array − An array containing one
or more arrays and values are accessed using multiple
indices
<?php
/* First method to create array. */
$numbers = array( 1, 2, 3, 4, 5);
foreach( $numbers as $value )
{ echo "Value is $value <br />"; }
/* Second method to create array. */
$numbers[0] = "one";
$numbers[1] = "two";
$numbers[2] = "three";
$numbers[3] = "four";
$numbers[4] = "five";
foreach( $numbers as $value )
{
echo "Value is $value <br />";
}
?>
<?php
/* First method to associate create array. */
$salaries = array("mohammad" => 2000, "qadir" => 1000, "zara" => 500);
echo "Salary of mohammad is ". $salaries['mohammad'] . "<br />";
echo "Salary of qadir is ". $salaries['qadir']. "<br />";
echo "Salary of zara is ". $salaries['zara']. "<br />";
/* Second method to create array. */
$salaries['mohammad'] = "high";
$salaries['qadir'] = "medium";
$salaries['zara'] = "low";
echo "Salary of mohammad is ". $salaries['mohammad'] . "<br />";
echo "Salary of qadir is ". $salaries['qadir']. "<br />";
echo "Salary of zara is ". $salaries['zara']. "<br />";
?>
<?php
$marks = array("mohammad" =>
array ( "physics" => 35,
"maths" => 30,
"chemistry" => 39),
"qadir" => array ("physics" => 30,
"maths" => 32,
"chemistry" => 29),
"zara" => array ("physics" => 31,
"maths" => 22,
"chemistry" => 39)
);
/* Accessing multi-dimensional array values */
echo "Marks for mohammad in physics : " ;
echo $marks['mohammad']['physics'] . "<br />";
echo "Marks for qadir in maths : ";
echo $marks['qadir']['maths'] . "<br />";
echo "Marks for zara in chemistry : " ;
echo $marks['zara']['chemistry'] . "<br />";
?>
Multidimensional
array
 In PHP, Object is a compound data type
(along with arrays). Values of more than one
types can be stored together in a single
variable. Object is an instance of either a
built-in or user defined class. In addition to
properties, class defines functionality
associated with data.
<?php
class SayHello
{
function hello()
{ echo "Hello World";
}
}
$obj=new SayHello;
$obj->hello();
?>
 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.
 Resources: The special resource type is not
an actual data type. It is the storing of a
reference to functions and resources external
to PHP. A common example of using the
resource data type is a database call.
 The if Statement
 Executes some code if one condition is true
 Syntax
 if (condition) {
code to be executed if condition is true;
}
<?php
$t = date("H");
if ($t < "20")
{
echo "Have a good day!";
}
?>
 The if...else Statement
 The if...else statement executes some code if a
condition is true and another code if that condition is
false
 Syntax
 if (condition) {
code to be executed if condition is true;
} else {
code to be executed if condition is false;
}
 <?php
$t = date("H");
if ($t < "20") {
echo "Have a good day!";
} else {
echo "Have a good night!";
}
?>
 The if...elseif...else Statement
 The if...elseif...else statement executes different codes for
more than two conditions
 Syntax
 if (condition) {
code to be executed if this condition is true;
} elseif (condition) {
code to be executed if first condition is false and this
condition is true;
} else {
code to be executed if all conditions are false;
}
 <?php
$t = date("H");
if ($t < "10") {
echo "Have a good morning!";
} elseif ($t < "20") {
echo "Have a good day!";
} else {
echo "Have a good night!";
}
?>
 The switch Statement
 The switch statement is used to perform different
actions based on different conditions.
 Syntax
 switch (n) {
case label1:
code to be executed if n=label1;
break;
case label2:
code to be executed if n=label2;
break;
case label3:
code to be executed if n=label3;
break;
...
default:
code to be executed if n is different from all
labels;
}
 <?php
$favcolor = "red";
switch ($favcolor) {
case "red":
echo "Your favorite color is red!";
break;
case "blue":
echo "Your favorite color is blue!";
break;
case "green":
echo "Your favorite color is green!";
break;
default:
echo "Your favorite color is neither red,
blue, nor green!";
}
?>
 Break Statement
 <?php
 $i = 0;
 for ($i = 0;$i <= 5;$i++)
 { if ($i==2)
 {
 break;
 }
 echo $i;
 echo "<br />";
 }
 echo "End of for loop" ;
 ?>
 Continue statement
 <?php
 $i = 0;
 for ($i = 0;$i <= 5;$i++)
 {
 if ($i==2)
 {
 continue;
 }
 echo $i;
 echo "<br />";
 }
 echo "End of for loop" ;
 ?>
 while loop
The while loop executes a block of code as long as
the specified condition is true.
 Syntax
 while (condition is true) {
code to be executed;
}
<?php
$x = 1;
while($x <= 5) {
echo "The number is: $x <br>";
$x++;
}
?>
 do...while Loop
 The do...while loop will always execute the block of
code once, it will then check the condition, and
repeat the loop while the specified condition is
true.
 Syntax
 do {
code to be executed;
} while (condition is true);
 <?php
$x = 1;
do {
echo "The number is: $x <br>";
$x++;
} while ($x <= 5);
?>
 For Loop
 The for loop is used when you know in advance how
many tim
 Syntax
 for (init counter; test counter; increment counter) {
code to be executed for each iteration;
}
 Parameters:
 init counter: Initialize the loop counter value
 test counter: Evaluated for each loop iteration. If it
evaluates to TRUE, the loop continues. If it evaluates to
FALSE, the loop ends.
 increment counter: Increases the loop counter value
<?php
for ($x = 0; $x <= 10; $x++) {
echo "The number is: $x <br>";
}
?>
 Foreach Loop
 The foreach loop works only on arrays, and is used
to loop through each key/value pair in an array.
 Syntax
 foreach ($array as $value) {
code to be executed;
}
 For every loop iteration, the value of the current
array element is assigned to $value and the array
pointer is moved by one, until it reaches the last
array element.
 <?php
$colors = array("red", "green", "blue", "yellow");
foreach ($colors as $value) {
echo "$value <br>";
}
?>
 <?php
 $a="hello";
 $m=var_dump($a);
 echo $m;
 ?>
 Type Juggling means dealing with a variable
type. In PHP a variables type is determined by
the context in which it is used. If an integer
value is assigned to a variable, it becomes an
integer.
 approach of PHP to deal with dynamically
changing value of variable is called type
juggling
 <?php
 $a=10;
 echo var_dump($a);
 echo"<br>";
 $b="10";
 echo gettype($b);
 echo"<br>";
 echo $c=$a+$b;
 echo"<br>";
 echo var_dump($c);
 ?>
 Exprression are any code that evaluates value
 An expression is a piece of code that
evaluates to a value.
 For eg,
 $x=$a+$b
 An Operator is a symbol that manipulates one
or more values ,usually producing a new
value in the process.
 Unary Operator
 Binary Operator
 Conditional Operator(Ternary Operator)
1. Arithmetic Operators
2. Autoincrement and Autodecrement Operator
3. Comparison Operaor
4. Logical Operators
5. Assignment Operators
6. Bitwise Operators
 7. Casting Operators
 Casting operator changes type of its operand
by force.
 For eg
<?php
$a="5";
echo var_dump($a);
$b=(int) $a;
echo var_dump($b);
?>
 8.Miscellanous operator
 Error Supression (@) Operator-
 In PHP @ symbol is defined as Error Control
Operator. When it is prefixed to any
expression, any error encountered by PHP
parser while executing it will be suppressed
and the expression will be ignored.
 <?php
 @$value=1/0;
 echo "Hello";
 ?>
 Execution
 PHP Supports one execution operator
backticks(``).
 PHP will attempt to execute the contents of
the backticks as a shellcommand
 Eg.
 $output=`ls -l`;
 Echo $output;
 Conditional
 (?:)
Syntax-exp1 ? Exp2 : exp3;
PHP History, Features, Variables, Data Types, Arrays, Loops

More Related Content

Similar to PHP History, Features, Variables, Data Types, Arrays, Loops

PHP MATERIAL
PHP MATERIALPHP MATERIAL
PHP MATERIALzatax
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisIan Macali
 
What Is Php
What Is PhpWhat Is Php
What Is PhpAVC
 
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 IndiaDeepak Rajput
 
Php using variables-operators
Php using variables-operatorsPhp using variables-operators
Php using variables-operatorsKhem Puthea
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPwahidullah mudaser
 
PHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet SolutionPHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet SolutionMazenetsolution
 
php&mysql with Ethical Hacking
php&mysql with Ethical Hackingphp&mysql with Ethical Hacking
php&mysql with Ethical HackingBCET
 
03phpbldgblock
03phpbldgblock03phpbldgblock
03phpbldgblockIIUM
 
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.pdfpkaviya
 

Similar to PHP History, Features, Variables, Data Types, Arrays, Loops (20)

PHP MATERIAL
PHP MATERIALPHP MATERIAL
PHP MATERIAL
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
 
What Is Php
What Is PhpWhat Is Php
What Is Php
 
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 using variables-operators
Php using variables-operatorsPhp using variables-operators
Php using variables-operators
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 
Php Learning show
Php Learning showPhp Learning show
Php Learning show
 
PHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet SolutionPHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet Solution
 
Php introduction
Php introductionPhp introduction
Php introduction
 
Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Introduction to php basics
 
php&mysql with Ethical Hacking
php&mysql with Ethical Hackingphp&mysql with Ethical Hacking
php&mysql with Ethical Hacking
 
Php
PhpPhp
Php
 
03phpbldgblock
03phpbldgblock03phpbldgblock
03phpbldgblock
 
Php essentials
Php essentialsPhp essentials
Php essentials
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
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
 
WT_PHP_PART1.pdf
WT_PHP_PART1.pdfWT_PHP_PART1.pdf
WT_PHP_PART1.pdf
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
php41.ppt
php41.pptphp41.ppt
php41.ppt
 
PHP InterLevel.ppt
PHP InterLevel.pptPHP InterLevel.ppt
PHP InterLevel.ppt
 

Recently uploaded

“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 

Recently uploaded (20)

“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 

PHP History, Features, Variables, Data Types, Arrays, Loops

  • 2.  Rasmus Lerdoff developed PHP in1994 and Released 1998.  PHP is a recursive acronym of Hypertext Pre-Processor.  In 1998 PHP3 was released  In 2000 PHP4 –improved speed and reliability  In 2004 PHP5 –Improved support for Object-Oriented Programming  In 2006 PHP5.2 was released  In 2009 PHP5.3 –Namespace Support  In 2012 PHP5.4-Improved with Performance and memory Requirement.  In 2013 PHP5.5-With Generators and finally blocks for exception handling  In 2014 PHP5.6-constatnt expression, character encoding etc.  In 2015 PHP7.0-Return type Declaration, spaceship operator etc.  In 2016 PHP7.1 –nullable types  In 2017 PHP7.2- Abstract method overriding  In 2018 PHP 7.3  Latest version of PHP is PHP7.4 released in 2019 offers to build applications that influence s everything form the website  PHP is a Server-side Scripting Language and used to create dynamic web pages.
  • 3.  Speed  Easy to Use/Simplicity  Stable  Platform Independent/Portability  Open Source  Built-in Database Connection Module  Powerful Library Support  Flexibility  Database Connectivity  Speed-UP Custom Web Application Development
  • 4.  PHP Script is executed on the server,and the plain HTML result is sent back to the browser.  PHP Script can be placed anywhere in the document .  PHP script starts with <?php And ends with ?> <?php //PHP Code goes here ?>
  • 5.  <?php  echo “hello world!”  ?>
  • 6.  Step 1 : Download the XAMPP Server From internet  Step 2: Install XAMPP Software  Step 3: Open and Click on the start button that is in front of Apache Text
  • 7.  Step 4: Create PHP file in htdocs directory which is resides in XAMPP directory[c:sampphtdocs].
  • 8.  Step 5:Save Program with extension .php in htdocs direcory , then open your browser and then type http://localhost/programname.php on address bar and press Enter key.
  • 9.  Variable:In PHP, a variable is declared using a $ sign followed by the variable name. Here, some important points to know about variables:  As PHP is a loosely typed language, so we do not need to declare the data types of the variables. It automatically analyzes the values and makes conversions to its correct datatype.  After declaring a variable, it can be reused throughout the code.  Assignment Operator (=) is used to assign the value to a variable.
  • 10.  A variable must start with a dollar ($) sign, followed by the variable name.  It can only contain alpha-numeric character and underscore (A-z, 0-9, _).  A variable name must start with a letter or underscore (_) character.  A PHP variable name cannot contain spaces.  One thing to be kept in mind that the variable name cannot start with a number or special symbols.  PHP variables are case-sensitive, so $name and $NAME both are treated as different variable.
  • 12. In PHP is_int() or is_integer() are used to test whether a value is an integer For example, <?php $a=10; if(is_int($a)) { echo "is an integer"; } ?>
  • 13. In PHP is_float() is used to test whether a value is a floating point number <?php $a=10.91; if(is_float($a)) { echo "is an floating point number"; } ?>
  • 14. In PHP is_string() is used to test whether a value is a String For example 1, <?php $a="good"; if(is_string($a)) { echo "is an string"; } ?> For example 2, <?php $a="Good"; echo "$a morning"; ?>
  • 15.  <?php  $a=true;  if(is_bool($a))  {  echo "is an boolean";  }  ?>
  • 16.  Numeric array − An array with a numeric index. Values are stored and accessed in linear fashion.  Associative array − An array with strings as index. This stores element values in association with key values rather than in a strict linear index order.  Multidimensional array − An array containing one or more arrays and values are accessed using multiple indices
  • 17. <?php /* First method to create array. */ $numbers = array( 1, 2, 3, 4, 5); foreach( $numbers as $value ) { echo "Value is $value <br />"; } /* Second method to create array. */ $numbers[0] = "one"; $numbers[1] = "two"; $numbers[2] = "three"; $numbers[3] = "four"; $numbers[4] = "five"; foreach( $numbers as $value ) { echo "Value is $value <br />"; } ?>
  • 18. <?php /* First method to associate create array. */ $salaries = array("mohammad" => 2000, "qadir" => 1000, "zara" => 500); echo "Salary of mohammad is ". $salaries['mohammad'] . "<br />"; echo "Salary of qadir is ". $salaries['qadir']. "<br />"; echo "Salary of zara is ". $salaries['zara']. "<br />"; /* Second method to create array. */ $salaries['mohammad'] = "high"; $salaries['qadir'] = "medium"; $salaries['zara'] = "low"; echo "Salary of mohammad is ". $salaries['mohammad'] . "<br />"; echo "Salary of qadir is ". $salaries['qadir']. "<br />"; echo "Salary of zara is ". $salaries['zara']. "<br />"; ?>
  • 19. <?php $marks = array("mohammad" => array ( "physics" => 35, "maths" => 30, "chemistry" => 39), "qadir" => array ("physics" => 30, "maths" => 32, "chemistry" => 29), "zara" => array ("physics" => 31, "maths" => 22, "chemistry" => 39) ); /* Accessing multi-dimensional array values */ echo "Marks for mohammad in physics : " ; echo $marks['mohammad']['physics'] . "<br />"; echo "Marks for qadir in maths : "; echo $marks['qadir']['maths'] . "<br />"; echo "Marks for zara in chemistry : " ; echo $marks['zara']['chemistry'] . "<br />"; ?> Multidimensional array
  • 20.  In PHP, Object is a compound data type (along with arrays). Values of more than one types can be stored together in a single variable. Object is an instance of either a built-in or user defined class. In addition to properties, class defines functionality associated with data.
  • 21. <?php class SayHello { function hello() { echo "Hello World"; } } $obj=new SayHello; $obj->hello(); ?>
  • 22.  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.  Resources: The special resource type is not an actual data type. It is the storing of a reference to functions and resources external to PHP. A common example of using the resource data type is a database call.
  • 23.  The if Statement  Executes some code if one condition is true  Syntax  if (condition) { code to be executed if condition is true; } <?php $t = date("H"); if ($t < "20") { echo "Have a good day!"; } ?>
  • 24.  The if...else Statement  The if...else statement executes some code if a condition is true and another code if that condition is false  Syntax  if (condition) { code to be executed if condition is true; } else { code to be executed if condition is false; }  <?php $t = date("H"); if ($t < "20") { echo "Have a good day!"; } else { echo "Have a good night!"; } ?>
  • 25.  The if...elseif...else Statement  The if...elseif...else statement executes different codes for more than two conditions  Syntax  if (condition) { code to be executed if this condition is true; } elseif (condition) { code to be executed if first condition is false and this condition is true; } else { code to be executed if all conditions are false; }  <?php $t = date("H"); if ($t < "10") { echo "Have a good morning!"; } elseif ($t < "20") { echo "Have a good day!"; } else { echo "Have a good night!"; } ?>
  • 26.  The switch Statement  The switch statement is used to perform different actions based on different conditions.  Syntax  switch (n) { case label1: code to be executed if n=label1; break; case label2: code to be executed if n=label2; break; case label3: code to be executed if n=label3; break; ... default: code to be executed if n is different from all labels; }
  • 27.  <?php $favcolor = "red"; switch ($favcolor) { case "red": echo "Your favorite color is red!"; break; case "blue": echo "Your favorite color is blue!"; break; case "green": echo "Your favorite color is green!"; break; default: echo "Your favorite color is neither red, blue, nor green!"; } ?>
  • 28.  Break Statement  <?php  $i = 0;  for ($i = 0;$i <= 5;$i++)  { if ($i==2)  {  break;  }  echo $i;  echo "<br />";  }  echo "End of for loop" ;  ?>
  • 29.  Continue statement  <?php  $i = 0;  for ($i = 0;$i <= 5;$i++)  {  if ($i==2)  {  continue;  }  echo $i;  echo "<br />";  }  echo "End of for loop" ;  ?>
  • 30.  while loop The while loop executes a block of code as long as the specified condition is true.  Syntax  while (condition is true) { code to be executed; } <?php $x = 1; while($x <= 5) { echo "The number is: $x <br>"; $x++; } ?>
  • 31.  do...while Loop  The do...while loop will always execute the block of code once, it will then check the condition, and repeat the loop while the specified condition is true.  Syntax  do { code to be executed; } while (condition is true);  <?php $x = 1; do { echo "The number is: $x <br>"; $x++; } while ($x <= 5); ?>
  • 32.  For Loop  The for loop is used when you know in advance how many tim  Syntax  for (init counter; test counter; increment counter) { code to be executed for each iteration; }  Parameters:  init counter: Initialize the loop counter value  test counter: Evaluated for each loop iteration. If it evaluates to TRUE, the loop continues. If it evaluates to FALSE, the loop ends.  increment counter: Increases the loop counter value <?php for ($x = 0; $x <= 10; $x++) { echo "The number is: $x <br>"; } ?>
  • 33.  Foreach Loop  The foreach loop works only on arrays, and is used to loop through each key/value pair in an array.  Syntax  foreach ($array as $value) { code to be executed; }  For every loop iteration, the value of the current array element is assigned to $value and the array pointer is moved by one, until it reaches the last array element.  <?php $colors = array("red", "green", "blue", "yellow"); foreach ($colors as $value) { echo "$value <br>"; } ?>
  • 34.  <?php  $a="hello";  $m=var_dump($a);  echo $m;  ?>
  • 35.  Type Juggling means dealing with a variable type. In PHP a variables type is determined by the context in which it is used. If an integer value is assigned to a variable, it becomes an integer.  approach of PHP to deal with dynamically changing value of variable is called type juggling
  • 36.  <?php  $a=10;  echo var_dump($a);  echo"<br>";  $b="10";  echo gettype($b);  echo"<br>";  echo $c=$a+$b;  echo"<br>";  echo var_dump($c);  ?>
  • 37.  Exprression are any code that evaluates value  An expression is a piece of code that evaluates to a value.  For eg,  $x=$a+$b
  • 38.  An Operator is a symbol that manipulates one or more values ,usually producing a new value in the process.  Unary Operator  Binary Operator  Conditional Operator(Ternary Operator)
  • 39. 1. Arithmetic Operators 2. Autoincrement and Autodecrement Operator 3. Comparison Operaor 4. Logical Operators 5. Assignment Operators 6. Bitwise Operators
  • 40.  7. Casting Operators  Casting operator changes type of its operand by force.  For eg <?php $a="5"; echo var_dump($a); $b=(int) $a; echo var_dump($b); ?>
  • 41.  8.Miscellanous operator  Error Supression (@) Operator-  In PHP @ symbol is defined as Error Control Operator. When it is prefixed to any expression, any error encountered by PHP parser while executing it will be suppressed and the expression will be ignored.
  • 42.  <?php  @$value=1/0;  echo "Hello";  ?>
  • 43.  Execution  PHP Supports one execution operator backticks(``).  PHP will attempt to execute the contents of the backticks as a shellcommand  Eg.  $output=`ls -l`;  Echo $output;