A variety of data types can be assigned to a variable in PHP(and beyond), ranging from simple strings and numbers to more complex data types such as arrays and objects. The PHP language offers support for eight primitive data types: Integer, Floating-point numbers, Strings, Booleans, Arrays, Objects, NULL; each of these data types is used to construct variables.
Let us now look in detail at the individual data types:
Integer
Integers are numbers without decimal points(Ex. 0, 1, 2, -1, -2, -3), and can be specified in:
Decimal notation (base 10)
Hexadecimal notation (base 16 with, prefixed with 0x)
Octal notation (base 8, with prefix 0)
Numbers may optionally be preceded by the - or + sign.
Strings
Strings are nothing more than a sequence of characters, where each is equivalent to one byte. A string can be up to 2GB in size, and can contain letters, numbers, and special characters. The simplest way to specify a string is to enclose it in single quotation marks ('Hello world!'), however, double quotation marks can also be used ("Hello world!").
Floating Point Numbers
I numeri in virgola mobile sono numeri frazionari o decimali, come quelli mostrati di seguito:
$x = 1.456
$y = 10.2e3
$z = 4E-10
Booleans
Booleans can represent only two types of values: 1(true) or 0(false).
Array
An array is a type of variable that can hold more than one value at a time, and is used to aggregate a set of related items such as, for example, a set of city or country names. Formally, an array is defined as an indexed data collection of values; each index (known as a key), uniquely represents the value it refers to.
Objects
A more complex type of data is objects. These allow not only the storage of data, but also contain information on how to process it. Each object is a specific instance of a class that serves as a model for it; objects are created precisely according to this model, using the keyword new. It is important to know that each object has properties and methods that correspond to those of its parent class: each instance is independent, with its own properties and methods, and can therefore be manipulated independently of other objects of the same class.
Null
The special value NULL is used to represent empty variables in the PHP language. A variable of this type is a variable with no data.
Top comments (0)