PHP Data
Type
PHP scripting language supports 13 primitive data
types. Data Types playimportant 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
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:
<?php
$x = “Computer Application!”;
$y = ‘Computer Application’;
echo $x;
echo “<br>”;
echo $y;
?>
Integer is a data type which contains non decimal
numbers.
Example:
<?php
$x = 59135;
var_dump($x);
?>
Float is a data type which contains decimal
numbers.
Example:
<?php
$x = 19.15;
var_dump($x);
?>
Boolean is a data type which denotes the possible
two states, TRUE or FALSE
Example:
<?php
$x = true;
$y = false;
echo $x;
echo $y;
?>
Array is a data type which has multiple values in
single variable. You will learn about arrays in the next chapter.
Example:
<?php
$cars =
array(“Computer”,”Laptop”,”Mobile”);
var_dump($cars);
?>
OUTPUT:
array(3) { [0]=> string(5)
“Computer “ [1]=> string(3) “Laptop “ [2]=> string(6) “Mobile “ }
The var_dump() system define function, returns
structured information (type and value) about variables in PHP.
In 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 ();
//show object properties
echo $school_obj ->sec;
?>
Null is a special data type which contains no
value:
<?php
$x = “COMPUTER APPLICATION!”;
$x = null;
var_dump($x);
?>
OUTPUT:
NULL
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
$handle = fopen(“note.txt”, “r”);
var_dump($handle);
echo “<br>”;
//Connect to MySQL database server
with default setting
$link = mysql_connect(“localhost”,
“root”, “”);
var_dump($link);
?>
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.