PHP Data Types

What are PHP Data Types:

Variables can store different types of data. A data type is a set of values and the allowable operations on those values.

PHP Has Eight data types:

Scalar types

  • boolean
  • integer
  • float
  • string

Compound types

  • array
  • object

Special types

  • resources
  • NULL

PHP String Type

A string is a sequence of characters, like “This is a sample line”.

PHP Integer Data Type

Integers are a subset of the real numbers. They are written without a fraction or a decimal component.
An integer data type is a non-decimal number between -2,147,483,648 and 2,147,483,647.

PHP Float Data Type

Floating-point numbers represent real numbers in computing. Real numbers measure continuous quantities, like weight, height, or speed. Floating-point numbers in PHP can be larger than integers and they can have a decimal point.

$s = "this is string example";  // $s is a string variable
echo $s."<br>";
$i = 10;   // $i is an integer variable 
echo $i."<br>";
$f = 1.3;  // $f is now a float (3.3)
echo $f."<br>";
$concat_i = $i."10 Little Piggies"; //  integer
echo $concat_i."<br>";

Run :

Tutorials Class - Output Window

this is string example
1010 Little Piggies

Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
No Content Found.
Interview Questions & Answers
What are the different data types in PHP?