Last Updated on Mar 21, 2023
What are the different data types in PHP?
- Main datatypes in PHP are :
- Float (also called double)
Let’s go through them one by one.
It’s a sequence of characters. An string can be inside "(double quotes) or '(single quotes). The single and double quotes are not the same. They both define the string but the way they define it is different.
The " will be interpreted by php but the ' will be saved as is. So what does it mean?
Let’s say we have a variable x with the value 10
$x = 10;
"My number is $x" php will interpret it and output is my number is 10
It’s a number without any decimal
integers can be positive or negative
$x = 10; $y = -10;
It’s a number with decimals
Floats can also be positive or negative
$x = 10.215; $y = -10.215;
TRUE or FALSE
Note that the words true and false are case-insensitive
True And TRUE and true are all the same
It’s a list. You can have multiple values all saved inside one variable
You can define it in 2 ways:
$x = array(1,2,"hello",true);
Heavy check mark$x = [1,2,"hello",true];
As you can see from the example above an array can have values in different types without any problem
It’s about object oriented programming (OOP) and in another day we’ll talk about it in details.
When it has no value assigned to it. It’s empty. It’s nothing. It’s null
it is a special data type that refers to any external resource. like file, database etc.
Now you know about different DataTypes in PHP.
I recommend you to open a PHP file and try defining different variables with different data types.
If you have any suggestions, questions, or opinions, please contact me. I’m looking forward to hearing from you!
- what are the main data types in PHP
- explanation about those datatypes