PHP Basic Tutorial
MySQL Connection
PHP data types are used to hold different types of data or values. PHP supports 8 primitive data types that can be categorized further in 3 types:
Scalar types are the simplest data types, representing a single value. There are 4 scalar data types in PHP.
Compound types are data types that can hold multiple values or complex data structures. There are 2 compound data types in PHP.
Special types that serve unique purposes, beyond storing scalar or compound values. There are 2 special data types in PHP.
A boolean (or bool) is a data type that represents two possible values: true or false. Booleans are often used in conditional statements and control structures to determine whether a condition is met or not.
Try it yourself
Note
Integer means numeric data with a negative or positive sign. It holds only whole numbers, i.e., numbers without fractional part or decimal points.
Rules for integer:
Try it yourself
A float (also known as a double or real number) is a data type that represents numbers with decimal points or numbers in scientific notation. Unlike integer, it can hold numbers with a fractional or decimal point, including a negative or positive sign.
Try it yourself
A string is a sequence of characters, used to store and manipulate text. Strings in PHP can include letters, numbers, symbols, or any combination of these.
String values must be enclosed either within single quotes or in double quotes. But both are treated differently.
Try it yourself
An array is a special variable that can hold multiple values at once. Arrays are one of the most powerful data types in PHP because they allow you to store and manipulate collections of values, whether they are numbers, strings, or even other arrays.
Try it yourself
Objects are the instances of user-defined classes that can store both values and functions. They must be explicitly declared.
Try it yourself
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.
This is an advanced topic of PHP, so we will discuss it later in detail with examples.
NULL is a special data type that represents a variable with no value. It is used to indicate that a variable has been intentionally left empty or that a function or operation has no value to return. NULL is different from other data types like strings, integers, or arrays, and it is a unique value in PHP.
Try it yourself
Note
If a variable is created without a value, it is automatically assigned a value of NULL.