Variable can store data of different types, and different types can do different things.
PHP support following data types:
- String
- Integer
- Float(double)
- Array
- Boolean
- Object
- Null
- Resource
PHP String
A String is a sequence of character like “Hello Microtech!!”;
A String can be any text inside quotes.You can use single or double quotes:
PHP Integer
An Integer is a whole number (without decimal).It is a number between -2,147483,648 and +2,147,483,647.
Rules for Integers:
- An Integer must haveat least one digit (0-9).
- An Integer can not contain comma or blank
- An Integer must have not decimal point
- An Integer can either positive or negative
- Integer can be spacified in three format :decimal (10-based), hexadecimal (16-based), or octal (8-based)
PHP Float
A float (floating point number) is a number with a decimal point or a number in exponential form.
PHP Boolean
A Boolean represent two possible states: TRUE or FALSE.
Booleans are often used in conditional testing. You will learn more about conditional testing in a later chapter of this tutorial.
PHP Array
An Array store multiple value on single variable.
[sam id=”4″ codes=”true”]
PHP Object
An object is data type which store data and information on how to process that data.
In PHP 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:
[nextpage title=”Program” ]
[message_box color=”yellow”]
<html>
<body>
<?php
$x = “Hello Microtech!”;
$y = ‘Hello Microtech!’;
echo $x;
echo “<br>”;
echo $y;
//The PHP var_dump() function returns the data type and value
$a=159;
var_dump($a);
$b=15.9;
var_dump($b);
$cars=array(“Audi”,”BMW”,”Toyota”);
var_dump($cars);
?>
</body>
</html>
[/message_box]
[/nextpage]
[nextpage title=”Output” ]
[message_box color=”yellow”]
Hello Microtech!
Hello Microtech!
int 159
float 15.9
array 0 => string 'Audi' (length=4) 1 => string 'BMW' (length=3) 2 => string 'Toyota' (length=6)
[/message_box]
[/nextpage]
[nextpage title=”Program” ]
[message_box color=”yellow”]
<html>
<body>
<?php
class Car {
function Car() {
$this->model = “AUDI”;
}
}
// create an object
$herbie = new Car();
// show object properties
echo $herbie->model;
?>
</html>
</body>
[/message_box]
[/nextpage]
[nextpage title=”Output” ]
[message_box color=”yellow”]
AUDI
[/message_box]
[/nextpage]