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:

A string is a sequence of characters enclosed inside quotes.

$name = "Robin Kumar";
echo $website;

Generally, we use string to store names, description, and many more things. In this example, we have assigned a person name to variable $name.

You can learn more about PHP String Tutorial.


PHP Integer:

Integers are whole numbers that can be used to assign person age, count, calculations and many purposes.

  • Numbers can be positive and negative.
  • Numbers can not be without fractional part i.e they cannot be decimal numbers.
  • The range of an integer or numbers can be between 2,147,483,648 and 2,147,483,647 i.e., -2^31 to 2^31.

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.

<?php 
$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 : http://ideone.com/42n2cm

Tutorials Class - Output Window

this is string example
10
1.3
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?