+1 vote
1.1k views
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 

7. NULL

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.

Example:

$x = “Computer Application!”;

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

Example: 

$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. 

Example: 

$x = 19.15;

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

Example: 

$x = true; 

$y = false;

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

Example: 

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

OUTPUT: 

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

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

Var_dump:

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.

<?php

class School {

function marks() {

$this->sec = “A”;

}

// create an object 

$school obj = new School ( );

?>

OUTPUT 

NULL

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

value: NULL

<?php $x = null;

?>

OUTPUT: 

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.

<?php

// Open a file for reading

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

var_dump($handle);

echo “<br>”;

// Connect to MySQL database server with default setting

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

var_dump($link);

?>

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.

Categories

...