PHP Example HTML Javascript jQuery Ajax CSS Java MORE

PHP Data type with example

We can assign different type of data to a variable. Data type means the various type of data that we assign to a variable.

PHP support various type of data type and all are also different from each other.

Below are the list of data type :

  1. String
  2. Integer
  3. Float (floating point numbers - also called double)
  4. Boolean
  5. Array
  6. Object
  7. NULL
  8. Resource

PHP String

A string can have letters, numbers, special characters and arithmetic values or combination of all.

Example

Example

<!DOCTYPE html> <html> <body> <?php  $a = "Hello world!"; $b = 'Hello world!'; echo $a; echo "<br>";  echo $b; ?> </body> </html>

Run It Yourself »

You can use both single quotation or double quotation

PHP Integer

All the number without decimal point is called as integer.

Example: 100, 2000 etc.

Example

<!DOCTYPE html> <html> <body> <?php   $a = 100; var_dump($a); ?>   </body> </html>

Run It Yourself »

PHP Float or Double

The Float or Double data type are number with decimal point.

Example: 29.6, 30.03 etc..

Example

<!DOCTYPE html> <html> <body> <?php   $a = 29.6; var_dump($a); ?>   </body> </html>

Run It Yourself »

Example

Input through variable

Run It Yourself »

PHP null

A variable of type null is a variable without any data.

Example

<!DOCTYPE html> <html> <body> <?php $a= NULL; var_dump($a); ?> </body> </html>

Run It Yourself »