ch-5 data type


Data Type
There are several data type works in php:
1. NULL
2. Boolean
3. Integer
4. Float
5. Array

NULL:
<?php
$a;
echo $a;
?>
Output:
Notice : Undefined variable: a
Because here you did not define variable value.In case, if you don’t want to define variable value, you have to assign NULL .
<?php
$a=NULL;
echo $a;
?>

Output: Empty screen i.e nothing print on screen.

<?php
$a=FALSE;
echo $a;
$b=TRUE;
echo $b;
?>

Boolean:
Boolean value hold conditional(TRUE and FALSE )value, where TRUE indicate 1 and FALSE indicate 0.
Example:1
<?php
$a=FALSE;
echo $a;
$b=TRUE;
echo $b;
?>
Output-1
Example:2
<?php
$a=FALSE;
echo $a;

if($a)
{
       echo "hello";
}
else
{
       echo "hii";
}
?>

Output:hii
Integer:
Integer data type consider whole number either positive or negative. Unlike C, php does not support unsigned Integer.
Php supports:
whole number, octal,hexadecimal ana binary number system.
For ex.
1.  Whole number
<?php
$a=867;
echo $a;
?>
Output:867
2. Octal Number
<?php
$a=0767;
echo $a;
?>

Output: 503
3.Hexa decimal
<?php
$a=0x767;
echo $a;
?>
Output:1895
3. Binary Number
<?php
$a=0b1010;
echo $a;
?>
Output: 10
4. Var_dump
Var_dump is a function used to show data type.ex:

<?php
$a=0b1010;
echo var_dump($a);
?>
Output:int(10)
float:
float are simply called as double or decimal data type.
<?php
$a=54.24;
echo $a;
?>
Output:54.24
Array:
Array is a list of group member, where indexing supports integer number.
<?php
$bar = array(2,3,4);
echo $bar[1];
?>
Output:3
Resource:
We can also use gettype function, where we can get type of data for ex.
<?php
$bar = gettype("Gita");
echo $bar;
?>
Output:string

Comments

Popular posts from this blog

ch-4 variable in php

Function