PHP Data Types
PHP Tutorial » PHP Data Types
What are PHP data types?
In PHP language, unlike other programming languages (C ++, Java, etc.), we do not have to declare the data type, because the PHP language automatically determines the assigned value.
PHP supports the following eight data types.:
- Integer
- String
- Float
- Boolean
- Object
- Array
- NULL
- Resource
These data types are used to construct variables.
PHP Integers
An integer data type is a non-decimal number, whole numbers, without a decimal point (...,-4, -3, -2, -1, 0, 1, 2, 3, 4, ...)
Integers can be specified in: decimal (base 10), hexadecimal (base 16), octal (base 8), or binary (base 2) notation
<?php
$x = 456; // decimal number
var_dump($x);
echo "<br>";
$y = -678; // a negative number
var_dump($y);
echo "<br>";
$z = 0xB1A; // hexadecimal number
var_dump($z);
echo "<br>";
$w = 2767; // octal number
var_dump($w);
?>
PHP Strings
A string is a sequence of characters, as "Hi, how are you".
A string can be any text inside single or double quotes:
<?php
$x = 'Hi, how are you';
echo $x;
echo "<br>";
$y = "Hi, how are you";
echo $y;
echo "<br>";
$z = 'Learn PHP tutorial, I\"ll be back soon.';
echo $z;
?>
Related subjects:
PHP syntax
What is an array
PHP variables
Echo and print statement
Tags: php data types check, php 7, variable type declaration, how many different data types are available in php? compound data types, special data types
What are PHP data types?
How many data types are in PHP?
What are the 7 data types?
What are the 4 main data types?
PHP Floating Point Numbers or Doubles
A float (floating point number as "floats", "doubles", or "real numbers") is a number with a decimal point or fractional.
<?php
$x = 4.264;
var_dump($x);
echo "<br>";
$y = 12.23e3;
var_dump($y);
echo "<br>";
$z = 3E-10;
var_dump($z);
?>
To see the result of the PHP code above please click Execute
PHP Boolean
Booleans has only two possible values either 1 (true) or 0 (false).
<?php
// Assign the value TRUE to a variable
$show_error = true;
var_dump($show_error);
?>
PHP Arrays
An array can stores multiple values in one single variable.PHP var_dump() function returns the data type and value:
<?php
$my_colors = array("Red", "Blue", "Green");
var_dump($my_colors);
echo "<br>";
$color_codes = array(
"Red" => "#ff0000",
"Blue" => "#0000ff",
"Green" => "#00ff00"
);
var_dump($color_codes);
?>
PHP Objects
An object data type is a data that not only allows storing data but also information on, how to process that data.
An object is a specific instance of a class which serve as templates for objects. Objects are created based on this template via the new keyword.
<?php
// Class definition
class greeting{
// properties
public $my_greeting = "Hi, how are you!";
// methods
function show_greeting(){
return $this->my_greeting;
}
}
// Create object from class
$message = new greeting;
var_dump($message);
?>
php data types check, php 7, php variable type declaration, how many different data types are available in php? compound data types in php, special data types in php
What are PHP data types?
How many data types are in PHP?
What are the 7 data types?
What are the 4 main data types?
PHP Data Types - Example - What are PHP data types? - php tutorial
This tool makes it easy to create, adjust, and experiment with custom colors for the web.

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.

Find here examples of creative and unique website layouts.

Find here examples of creative and unique website CSS HTML menu.