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);
?>