PHP 5 Data Types
String (String), Integer (Integer), Float (float), Boolean (Boolean), Array (array), Object (Object), NULL (null).
PHP string
A string is a sequence of a string of characters, like "Hello world!".
You can put any text in single quotes and double quotes:
Examples
$ X = "Hello world!";
echo $ x;
echo "<br>";
$ X = 'Hello world!';
echo $ x;
?>
try it"
PHP Integer
Integer is not a decimal number.
Integer rules:
- Integer must have at least one number (0-9)
- Integer can not contain commas or spaces
- Integer without a decimal point
- Integer can be positive or negative
- Integer can be specified in three formats: decimal, hexadecimal (prefixed with 0x) or octal (prefix 0).
In the following examples we will test different numbers. PHP var_dump () function returns the data type of the variable and value:
Examples
$ X = 5985;
var_dump ($ x);
echo "<br>";
$ X = -345; // negative
var_dump ($ x);
echo "<br>";
$ X = 0x8C; // hexadecimal number
var_dump ($ x);
echo "<br>";
$ X = 047; // octal number
var_dump ($ x);
?>
try it"
PHP Float
Floating point numbers are numbers with a fractional part, or exponential form.
In the following examples we will test different numbers. PHP var_dump () function returns the data type of the variable and value:
Examples
$ X = 10.365;
var_dump ($ x);
echo "<br>";
$ X = 2.4e3;
var_dump ($ x);
echo "<br>";
$ X = 8E-5;
var_dump ($ x);
?>
try it"
PHP boolean
Boolean can be either TRUE or FALSE.
$ Y = false;
Boolean conditions commonly used for judgment. In the next chapter you will learn more about the controlled conditions tutorial.
PHP array
An array of multiple values can be stored in a variable.
Creating an array In the following example, and then use the PHP var_dump () function returns the data type and value of the array:
In the next chapter you will learn more about the array of knowledge.
PHP object
Object data type can also be used to store data.
In PHP, the object must be declared.
First, you must use the class keyword to declare a class object. Class structure can contain attributes and methods.
Then we define the data types in the class, and then use an instance of the class data type:
Examples
class Car
{
var $ color;
function Car ($ color = "green") {
$ This-> color = $ color;
}
function what_color () {
return $ this-> color;
}
}
?>
try it"
The above example PHP keyword this is a pointer pointing to the current object instance does not point to any other object or class.
You will learn more about the object of knowledge in the following sections.
PHP NULL value
NULL value represents a variable with no value. NULL is the data type of the value NULL.
NULL value indicates whether a variable is null. The same data can be used to distinguish between a null value and NULL values.
NULL values can be cleared by setting the variable variable data: