0% found this document useful (0 votes)
88 views

PHP, Introduction and Datatype

This document provides an introduction to PHP including its data types. It discusses PHP syntax, requirements, and the different data types PHP supports including strings, integers, floats, booleans, arrays, objects, NULL values, and resources. Examples are provided for each data type.

Uploaded by

Lovedeep kaur
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views

PHP, Introduction and Datatype

This document provides an introduction to PHP including its data types. It discusses PHP syntax, requirements, and the different data types PHP supports including strings, integers, floats, booleans, arrays, objects, NULL values, and resources. Examples are provided for each data type.

Uploaded by

Lovedeep kaur
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

DEPARTMENT OF COMPUTER

SCIENCE
PRESENTATION
TOPIC-PHP, INTRODUCTION AND
DATATYPE

SUBMITTED BY: SUBMITTED TO:


Miss. Rupneet Kaur Harpreet Kaur
MCA 1st
19071213
INTRODUCTION TO PHP
• PHP is a server side scripting language that is
used to develop static websites or dynamic
websites or web application. PHP stands for
Hypertext Pre-Processor, that earlier stood for
Personal Home Page.
• PHP script can only be interpreted on a server
that has PHP installed.
• The client computer accessing the PHP scripts
require a web browser only.
PHP SYNTAX

• A PHP script can be placed anywhere in the document.


• A PHP script start with <?php and ends with ?>:
<?php
//PHP code goes here
?>
• The default file extension for PHP files is “. php”.
• A PHP file normally contains HTML tags, and some PHP scripting code.
We have an example of a simple PHP file, with a PHP script that uses a built-in PHP function “echo” to output the text “Hello
World” on a web page.
Example
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
 
<?php
Echo “Hello World!”;
?>
 
</body>
</html>
PHP Requirements

Since it is safe to assume that you have access to a


browser, a computer, an electrical socket to plug in
your computer, and a power plant to generate the
power available to your electrical socket, then the
only remaining requirements to run PHP are either
one of the following two options.
• A web host that supports PHP.
• A web server and PHP installed on your own
computer.
PHP Data type

Variables can store data of different types, and different data types can
different things.
 
PHP supports the following data types:
 
1. String
2. Integer
3. Float
4. Boolean
5. Array
6. Object
7. NULL
8. Resource
 
 
 
PHP String
• A string is a sequence of characters, like “Hello world!”.
• A string can be any text inside quotes. You can use single or double
quotes.
Example
<?php
$x = “Hello world!”;
$y = ‘Hello world!’;
 
echo $x;
echo “<br>”;
echo $y;
?>
PHP integer

An integer data type is a non-decimal number between -2,147,483,648 and


2,147,483,647.
Rules of integers:
• 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.
In the following example $x is an integer. The PHP var_dump() function returns the
data type and value.
Example
<?php
$x = 5985;
var_dump($x);
?>
PHP Float

• A float (floating point number) is a number


with a decimal point or a number in
exponential form.
Example
<?php
$x = 10.365;
var_dump($x);
?>
PHP Boolean
A Boolean represents two possible states:
TRUE or FALSE.
$x = true;
$y = false;
Booleans are often used in conditional
testing.
PHP Array

An array stores multiple values in one single


variable.
Example
<?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.
Example
<?php
Class car
{
Function car()
{
$this->model=”VM”;
}
}
PHP NULL Value

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.
Variables can also be emptied by setting the value to NULL:
Example
<?php
$x = “Hello world”;
$x = null;
var_dump($x);
?>
PHP Resource

• 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.
THANKYOU

You might also like