PHP data types- How to define and initialize
PHP data types support a total of eight primitive data types: Integer, Floating-Point or Float, String, Booleans, Array, Resource, Object, and NULL. These types of data are used for making variables. Now let’s talk about each in-depth.
A Boolean stands for two possible states: either TRUE (1) or FALSE (0). In conditional testing, booleans are also used. such as if.. else.., loop, etc.
Initializing the boolean value to variables:
$a = false;
$b = true;
An array is a variable that can store multiple values in a single variable. The formal meaning of an array is the indexed set of data values. Every index of an array (also known as the key) is special and refers to a corresponding value.
How to define :
How to Initialization :
we can define an array using array keyword followed by Parentheses () or we can define an array using square Brackets .
An object is a type of data that allows data to be stored as well as information about how to process the data. An object is a particular instance of a class that serves as object templates. Objects are generated using the new keyword, based on this template. In PHP, an object must be explicitly declared. Each object has properties and methods which match those of its parent class. Every object instance is fully autonomous, with its own properties and methods, and can, therefore, be manipulated independently of other objects of the same class. First, we have to define the object type. We use the class keyword for this. A class is a structure that can include properties and methods.
A string is a series of characters, such as “Hello world!”. Any text within quotes can be a string. Single or double quotes can be used. A string can contain letters, numbers, and special characters and can be up to 2 GB in size (maximum of 2147483647 bytes).
An integer data form is a non-decimal number ranging from -2,147,483,648 to 2,147,483,647. Whole numbers, without a decimal point (…, -2, -1, 0, 1, 2, …).Integers can be specified in decimal (base 10), hexadecimal (base 16 – prefixed with 0x) or octal (base 8 – prefixed with 0) optionally followed by a symbol (- or +).
Rules for integer :
An integer should have a minimum of one digit
An integer may either be negative or positive
An integer does not have one decimal point
A float (a floating-point number) is a number in exponential form with a decimal point or number.
Null is a special category of data that can only have one value: the End. A data form variable NULL is a variable that does not have a value assigned to it.
A resource is a special variable that holds an external resource relation. Usually, resource variables contain special handlers for opened files and connections to databases. A typical example of using the form of resource data is a call to the database. We are not going to speak about the type of resource here, as it’s an advanced subject.