Free cookie consent management tool by TermsFeed Generator PHP DataTypes | Amir Kamizi
AMIR KAMIZI
Home Blog Courses Books Newsletter Store Membership Buy me a coffee
PHP DataTypes

PHP DataTypes

Last Updated on Mar 21, 2023

What are the different data types in PHP?

  • Main datatypes in PHP are :
  • String
  • Integer
  • Float (also called double)
  • Boolean
  • Array
  • Object
  • NULL
  • Resource

Let’s go through them one by one.

String

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' output is my number is $x

"My number is $x" php will interpret it and output is my number is 10

Integer

It’s a number without any decimal
Like 0,10,500,6254965
integers can be positive or negative

$x = 10;
$y = -10;

Float

It’s a number with decimals
Like 10.5,0.25,0.000625,15236.21,12.00
Floats can also be positive or negative

$x = 10.215;
$y = -10.215;

Boolean

TRUE or FALSE
Note that the words true and false are case-insensitive
So
True And TRUE and true are all the same

Array

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);

or

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

Object

It’s about object oriented programming (OOP) and in another day we’ll talk about it in details.

NULL

When it has no value assigned to it. It’s empty. It’s nothing. It’s null

Resource

it is a special data type that refers to any external resource. like file, database etc.

https://youtu.be/mREk56vgkxs

Conclusion

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!

Key takeaways

  • what are the main data types in PHP
  • explanation about those datatypes

 

Category: programming

Tags: #php

Join the Newsletter

Subscribe to get my latest content by email.

I won't send you spam. Unsubscribe at any time.

Related Posts

undo git merge the easy way and then undo the undoing! (video)
Nov 27, 2022 programming

undo git merge the easy way and then undo the undoing! (video)

we are going to talk about how to undo git merge and then we talk about how to undo the undoing ...

9 Min Read Read More
PHP Loops
Mar 21, 2023 programming

PHP Loops

Today we are going to learn about loops in PHP. Loop is another important concept in programming and we are going to learn everything about loops in PHP. ...

11 Min Read Read More
PHP isset and empty
Mar 21, 2023 programming

PHP isset and empty

Today we are going to learn about isset and empty in PHP. isset and empty are two functions that help us check the existence of a value. They are way more useful than you think. ...

5 Min Read Read More
Alpine.js Beginner to Advanced 2025: Everything You Need to Know
Jul 18, 2025 programming

Alpine.js Beginner to Advanced 2025: Everything You Need to Know

JavaScript frameworks have exploded in popularity over the past decade, but not every project needs—or benefits from—the complexity of tools like React or Vue. Sometimes, all you want is to sprinkle interactivity into your HTML without a heavy build process. This is exactly where Alpine.js shines. ...

29 Min Read Read More

Recommended Courses

Introduction to Machine Learning in PHP

Introduction to Machine Learning in PHP

Learn to Build Different Machine Learning Models Easily ...

PHP Tutorial Beginner to Advanced

PHP Tutorial Beginner to Advanced

Learn everything you need to start a successful career as a PHP developer ...