PHP Guide. Everything You Need To Know About PHP Datatypes And VariablesPosted by TotalDC
Now that we looked at what PHP is. Let’s start diving deeper into it and talk about PHP datatypes and variables.
Data Types in PHP
PHP doesn’t have explicit defined data types. PHP determines the data type by analyzing the attributes of given data. PHP supports following data types:
- Integer – whole numbers. In example -2, 0, 3, 58.
- Floating point number – decimal numbers in example 3.14. They are also known as double or real numbers.
- Character string – In example Hello World.
- Boolean – true or false statements.
- Array – named and indexed collections of other values.
- Object – instances of programmer-defined classes, which can package up both other kinds of values and functions that are specific to the class.
Variables in PHP
Variable Naming Rules in PHP
- All variables in PHP start with a
$sign, followed by the name of the variable.
- A variable name must start with a letter or the underscore character
- A variable name cannot start with a number.
- A variable name in PHP can only contain alpha-numeric characters and underscores (
- A variable name cannot contain spaces.