PHP New
PHP New
PHP New
PHP Introduction
• PHP started out as a small open source project that evolved as
more and more people found out how useful it was. Rasmus
Lerdorf unleashed the first version of PHP way back in 1994.
• PHP is a recursive acronym for "PHP: Hypertext Preprocessor".
• PHP is a server side scripting language that is embedded in
HTML. It is used to manage dynamic content, databases,
session tracking, even build entire e-commerce sites.
• It is integrated with a number of popular databases, including
MySQL, PostgreSQL, Oracle, Sybase, Informix, and Microsoft
SQL Server.
What Can PHP Do?
<?php
//your code here
?>
<!DOCTYPE>
<html>
<body>
<?php
echo "<h2>Hello First PHP</h2>";
?>
</body>
</html>
• printing string
<?php
echo "Hello by PHP echo";
?>
<?php
define("MESSAGE","Hello JavaTpoint PHP",true);
//not case sensitive
echo MESSAGE;
echo message;
?>
<?php
define("MESSAGE","Hello JavaTpoint PHP",false);//case sensitive
echo MESSAGE;
echo message;
?>
PHP Data Types
• Variables can store data of different types, and
different data types can do different things.
• PHP supports the following data types:
• String
• Integer
• Float (floating point numbers - also called double)
• Boolean
• Array
• Object
• NULL
• Resource
Literals..
• All strings must be enclosed in single of double
quotes: ‘Hello’ or “Hello”.
• Numbers are not in enclosed in quotes: 1 or 45 or
34.564
• Booleans (true/flase) can be written directly as
true or false.
• The PHP var_dump() function returns the data type and
value: <?php
$x = 5985;
var_dump($x);
?>
PHP Array
• 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("Volvo","BMW","Toyota");
var_dump($cars);
?>
PHP Object
• An object is a data type which stores data and
information on how to process that data.
• In PHP, an object must be explicitly declared.
• First we must declare a class of object. For this, we
use the class keyword. A class is a structure that can
contain properties and methods:
• <?php
class Car {
function Car() {
$this->model = "VW";
}
}
// create an object
$herbie = new Car();
2. <?php
$x = 10;
echo $x;
?>
Comparison Operators Operator Name Example Result
• Comparison
operators are used
== Equal $x == $y Returns true if $x is equal to $y
to determine
equality or != Not equal $x != $y Returns true if $x is not equal to $y
difference between
variables or values.
<> Not equal $x <> $y Returns true if $x is not equal to $y
3. <?php
$x = 100; > Greater than $x > $y Returns true if $x is greater than $y
$y = "100";
var_dump($x == $y); < Less than $x < $y Returns true if $x is less than $y
<= Less than or equal to $x <= $y Returns true if $x is less than or equal to $y
Logical Operators
• Logical operators are used to determine
the logic between variables or values.
Operato
r Name Example Result
|| Or $x || $y True if either $x or $y
is true
6. <?php
$txt1 = "Hello";
$txt2 = " world!";
echo $txt1 . $txt2;
?>
PHP Array Operators
• Q7 , Q8 & Q9