PHP Data Types | How Many Types in PHP | Data Types - Cyber Thieve

Data Types in PHP

PHP (Hypertext Processor) is a general-purpose scripting language and interpreter that is freely available and widely used for web development. The language is used primarily for server-side scripting, although it can also be used for command-line scripting and, to a limited degree, desktop applications. The acronym PHP was originally derived from Personal Home Page Tools, but it now stands for PHP Hypertext Preprocessor, which the PHP Group's documentation describes as a "recursive acronym."

PHP supports the following data types:

  • int
  • float
  • bool
  • string
  • array
  • object
  • null
  • resources


integer data type :- 

An integer data type is a non-decimal number between -2147483648 and 2147483647 in 32 bit systems, and between -9223372036854775808 and 9223372036854775807 in 64 bit systems. A value greater (or lower) than this, will be stored as float, because it exceeds the limit of an integer.

Rules for 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
string data type :-

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:
A string is a non-numeric data type. It holds letters or any alphabets, numbers, and even special characters. String values must be enclosed either within single quotes or in double quotes.

Float data type :-

A float (floating point number) is a number with a decimal point or a number in exponential form.
In the following example $x is a float. The PHP var_dump() function returns the data type and value.
A float is a number with a decimal point or a number in exponential form. 2.0, 256.4, 10.358, 7.64E+5, 5.56E-5 are all floats. The float data type can commonly store a value up to 1.7976931348623E+308 (platform dependent), and have a maximum precision of 14 digits.

Boolean data type :-

A Boolean represents two possible states: TRUE or FALSE.
The boolean values are called true and false in php. In the case of true , the output is 1 . While with the false , it does not show any output. It is worth noting that the browser always renders these values in strings.
Array data type :-

PHP array is an ordered map. It is used to hold multiple values of similar type in a single variable.

There are 3 types of array in PHP.
  1. Indexed Array
  2. Associative Array
  3. Multidimensional Array

PHP Indexed Array

PHP index is represented by number which starts from 0. We can store number, string and object in the PHP array. All PHP array elements are assigned to an index number by default.

PHP Associative Array
We can associate name with each array elements in PHP using => symbol.

PHP Multidimensional Array
PHP multidimensional array is also known as array of arrays. It allows you to store tabular data in an array. PHP multidimensional array can be represented in the form of matrix which is represented by row * column.

Object data type :-
A class is a template for objects, and an object is an instance of a class. When the individual objects are created, they inherit all the properties and behaviors from the class, but each object will have different values for the properties.

null data type :-

When the individual objects are created, they inherit all the properties and behaviors from the class, but each object will have different values for the properties.
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


Resources data type :-

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.
Resources are not the exact data type in PHP. Basically, these are used to store some function calls or references to external PHP resources. For example - a database call. It is an external resource.

NOTE : If you find any mistake or weakness in my article please help us to improve our content.

Also Read Our Best Article on Networking :

Presentation Layer
Application Layer
Session Layer

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Ok, Go it!