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.
