What are the PHP datatypes and their usage in php?

PHP Data Types

There are different types of values we can assign to a PHP variable including simple string to more complex data types like arrays or objects. Because it supports eight data types as Integer, Float, String, Booleans, Array, NULL, resource, and Object. We can use these PHP data types to declare variables. Their list is given below:

  1. String
  2. Integers
  3. Boolean
  4. Float
  5. Array
  6. Object
  7. NULL
  8. Resource

So let us know about each one of these data types in detail.

String

The string data types are used to store letters, any alphabets, numbers, and even special characters. Thay stores values in single/double quotes during variable declaration.

PHP Integers

Integers are the numbers without a decimal point like as -1, 0, 1, 2, +3, 4, 5, etc. Integers are specified in decimal (base 10), hexadecimal (base 16 – prefixed with 0x) or octal (base 8 – prefixed with 0) notation.

PHP Boolean

The boolean data type is the simplest data type that works as an electric switch button. It holds only two types of values: TRUE i.e 1 or FALSE i.e 0. If the condition is correct then it returns TRUE otherwise it returns FALSE.

Float

The floating data types are numbers with a decimal point. It can stores numbers with a fractional or decimal point, along with a negative or positive sign like 36.50, 10.34, etc.

Array

An array is a variable that can store more than one value at a time in a single variable. It is useful to store a series of related items together, for example, a set of class students’ names or marks.

An array is normally defined as an indexed collection of data values. Each index known as the key of an array is unique and points to a value.

Objects

The object data type not only stores data but also information on, how to process that data to process. The object is an instance of a class. By using a ‘new’ keyword we can create an object of any class.

All objects have properties and methods corresponding to those of their parent class. Every object is completely independent, with its own properties and methods, so we can manipulate independently.

Null Data type

The “NULL” data type represents a variable with no value or blank value. It is case sensitive so there is a naming convention of writing it in capital letters.

Resources

The resource is a special variable that holds the reference of an external resource. These variables hold special handlers to opened files and database connections, etc.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top