PHP | Data Types

Values & Types | PHP Guide

In PHP, Data types are used to declare one particular type of data as in all programming languages. Data Types define the type of data a variable can store.
PHP supports 8 primitive data types that can be categorized further in 3 types:

  1. Scalar Types (predefined)

This particular data types holds only single value. There are 4 scalar data types in PHP.

  • String

A string is a non-numeric data type. It holds letters or any alphabets, numbers, and even special characters. String must be written either within single quotes or in double quotes, both acceptable.

  • Integers

Integers hold only whole numbers including positive and negative numbers.

Rules for integers:

An integer must have at least one digit.

An integer must not have a decimal point.

An integer can be either positive or negative.

  • Float

Float is a number with a decimal point or a number in exponential form. It can hold numbers with a fractional or decimal point, including a negative or positive sign.

  • Booleans

Booleans are one of the simplest data type in PHP. It hold only 2 values TRUE and FALSE. It is mainly used in conditional statements.

2. Compound Types

This particular data types holds multiple values. There are 2 compound data types in PHP.

  • Array

An array is a compound data type that can store multiple values with same data type in a single declared variable.

  • Objects

Objects are the instances of user-defined classes that can hold both values and functions and information for data processing specific to the class.

Objects are declared and created from the new keyword.  

3. Special Types

There are 2 special data types in PHP.

  • Null

These are special types of variables that can hold only one value NULL, which is intentional declared to be null. There is a convention of writing it in capital letters as it is case sensitive written in capital letters.

  • Resources

Resources in PHP are not an exact data type. These are basically used to store references to some function call or to external PHP resources. This is an advanced topic of PHP.

Let’s take an example for all above data types:

Summary

After reading this blog, you should have a better clear concept of some of the major data types that are available in PHP. Each of these data types will become important with a particular role as you develop programming projects in the PHP language.

I hope you find this particular blog helpful and informative about data types in PHP.

Keep practicing and exploring, there are lot more to know.

Thank you!!

Related Posts

JAVA SCRIPT VARIABLE AND DATATYPE.

What is Variable ? Variable is just like a container which store the value into it . ex- var x=6; let y=x+z; In above example x and…

Read More

JavaScript Intro And Basic

JavaScript JS is a part of web page that’s defines all the action perform on the web pages. JS is a programming language with oop concepts. JS…

Read More

jQuery Basic

jQuery is a JavaScript library. The purpose of jQuery is to make it much easier to use JavaScript on the website. jQuery syntax is tailor made for…

Read More

Why PHP Is Still So Important for Web Development?

PHP (Hypertext Preprocessor) is a general-purpose scripting language that can be used to develop dynamic websites. It was from the first server-side languages that could be embedded…

Read More

What is Loops in JavaScript?

Looping in programming languages is a feature which facilitates the execution of a set of instructions/functions repeatedly while some condition evaluates to true. For example, suppose we…

Read More

What is JavaScript?

JavaScript is a scripting or programming language that allows you to implement complex features on web pages every time a web page does more than just sit…

Read More