Data Types In PHP

PHP DATA TYPE

Data type simply means store different type of data and its uses. In PHP there are 8 data types as follows.

  1. String
  2. Integer
  3. Float
  4. Boolean
  5. Null
  6. Array
  7. Object
  8. Resource

#1 PHP String 

String means group or sequence of characters. Ex  Hello World! 

You can store string inside PHP variable using single quotation or  double quotation.

<?php

echo $name=”Virat”;

echo $surname=’Kohli’;   

?> 

#2 PHP Integer

In this data type variable hold number without a decimal and its range is fixed between  -2,147,483,648 and 2,147,483,647.

Here is some rule of Integer

  • One digit required
  • Number is positive or negative
  • No decimal point

<?php

$a=10;

$b=20;

echo $sum=$a+$b; // output : 30

?>

Tip

For an integer, you have don’t want to define this is an integer value you can use single quotation or double quotation mark PHP automatically get what datatype you want to use

#3 Float

The float is number with a decimal point like 10.50.  In float value required decimal point and some number after point

<?php

var_dump(10.50); // Output : float(10.50)

?>

#4 Boolean

The boolean mean true or false. other mean 1 or 0.

Boolean simply use testing condition. if the condition is true then do this else do this