AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

PHP Data Types


<< Previous Page
PHP Syntax
Next Page >>
PHP echo - print

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.:

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

Example (this is HTML - PHP editor, change text, values on this window)
<?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:

Example (this is HTML - PHP editor, change text, values on this window)
<?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.

Example (this is HTML - PHP editor, change text on this window)
<?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).

Example (this is HTML - PHP editor, change text on this window)
<?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:

Example (this is HTML - PHP editor, change text on this window)
<?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.

Example (this is HTML - PHP editor, change text on this window)
<?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

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


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


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Home
PHP Introduction
PHP Install
PHP Syntax
PHP Variables
PHP Echo and Print
PHP Data Types
PHP String Function
PHP Constants
PHP Operator Types
PHP If Else and Elseif
PHP Switch
PHP While Loops
PHP Loop For Do Foreach
PHP Array
Convert Array to String
PHP Function
PHP GET and POST
PHP Date/Time Functions
PHP Login
PHP Delete Element
PHP eregi_replace()
PHP mysql_query()
PHP Errors to Display
PHP Loop For Do Foreach

PHP forms
PHP Form Example
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


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


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Upload Image, display, edit and delete i...
Login Form with Image background...
How to Create an Image with Transparent ...
Portfolio Gallery Website with filtering...
Simple pagination script PHP MySQLi...
Center Image in div...
Image Hover Overlay Fade...
Sticky image / element / div on scroll...
Responsive images...
Create rounded image in HTML CSS...
Add border around image...
Position Text Over an Image HTML CSS res...
Create a Slideshow Images Gallery...
Create a Sticky Sidebar...
Search bar using CSS HTML...
Shrink Navigation Menu on Scroll...
How to Create Accordion HTML Templates...
Dropdown menu in the navigation bar...
Responsive Top Navigation Bar with mobil...
Split horizontal navigation bar...