Friday 22 April 2011

Data Types in PHP



Types of Data Types in PHP

In PHP we have four types of data types.
1.Scalar Data Type.
2. Compound Data Type.
3. Special Data Type

Scalar Data Type: Scalar data type is divided into four types.


i)                    Boolean Data Type: This data type can hold true or false values.
is_bool -> This function checks the input variable is, Boolean or not.
Ex:
<?php
$x="false";
$x=(bool)$x;
echo is_bool ($x);
?>
ii)                  Integer Data Types: Integer data types holds the numeric value.
is_int -> By using this function we can check the input type variable is integer or not.
Ex:
<?php
$x="123";
$x=intval($x);
echo is_integer ($x);
?>
iii)                Float Data Type: Float variable holds the decimal values.
is_float -> By using this function we can check whether the input variable is float number or not.
(float)var-> to convert a variable into floating point numbers.
php.ini -> Precision is a directive to specify the number of significant digits > display in a floating point number. The default value is “12”.
iv)                 String Data Type: A string variable holds the collection of the characters. We can declare the string in two ways using single quotation(‘) and double quotations(“) using heredoc type.
Ex:
<?php
$x=100;
echo 'value of x is $x';
echo "value of x is $x";
?>
*By using this syntax we can design the html forums in php script.
<?php
$x=100;
echo <<<abcd
<input type="button" value="click">
abcd
?>


Compound Data types

Array Data Types: Array is the collection of elements. PHP is loosely typed language. That is why we can store any type of element in array.
Ex:
<?php
$arr=array('10','20','30');
echo $arr
?>
Special Data Types : Resource variable refreshes the external resources like data loose connections, file pointers, ftp connections.
Null Data Types : In php null is not a value, we can consider a variable as null variable based on 3 conditions.
i)                     The variable is not set with any variable.
ii)                   The variable is set with the null value.
iii)                  The value of the variable is deleted by using unset function.
*is_null: By using this function we can check whether the variable is null or not.
Ex:
<?php
$sno=100;
echo is_null($sno);
unset($no);
echo is_null($sno);
?>
In above script 1st is_null is not null 2nd is_null is a null.

3 comments:

  1. what is the use of Database & how to we use ??? http://www.danphp.com/p/php-notes-php-tutorial-notes.html

    ReplyDelete
  2. please add installation and execution images

    ReplyDelete
  3. please add installation and execution images(PHP)

    ReplyDelete