+1 vote
in Introduction to Hypertext Pre-Processor by (54.6k points)
closed by

Discuss in detail about PHP data types?

1 Answer

+2 votes
by (51.3k points)
selected by
Best answer

PHP Data type:

PHP scripting language supports 13 primitive data types. Data Types plays important role in all programing languages to classify the data according to the logics. 

PHP supports the following data types.

1. String 

2. Integer 

3. Float 

4. Boolean 

5. Array 

6. Object 


8. Resource

1. String: String is a collection of characters within the double or single quotes like “Computer Application” or ‘Computer Application’. Space is also considered as a character.


$x = “Computer Application!”;

2. Integer: Integer is a data type which contains non decimal numbers


$x = 59135;

The var_dump( ) system define function, returns structured information (type and value) about variables in PHP.

3. Float: Float is a data type which contains decimal numbers. 


$x = 19.15;

4. Boolean: Boolean is a data type which denotes the possible two states, TRUE or FALSE


$x = true; 

$y = false;

5. Array: Array is a data type which has multiple values in single variable.


Scars = array(“Computer” , “Laptop” , “Mobile”);


array(3) {[0]=> string(5) “Computer” [1]=> 

string(3) “Laptop “ [2]=> string(6)” Mobile”} 


The var_dump( ) function is used to dump information about a variable. This function displays structured information such as type and value of the given variable. Arrays and objects are explored recursively with values indented to show structure.

6. Object: PHP object is a data type which contains information about data and function inside-the class.


class School {

function marks() {

$this->sec = “A”;


// create an object 

$school obj = new School ( );




7. NULL: Null is a special data type which contains a single,

value: NULL

<?php $x = null;




8. Resources: Resource is a specific variable, it has a reference to an external resource. These variables hold specific handlers to handle files and database connections in respective PHP program.


// Open a file for reading

Shandle = fopen(“note.txt” , “r”);


echo “<br>”;

// Connect to MySQL database server with default setting

Slink = mysql_connect(“localhost” , “root” , “”); 



Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.