Type of Variable

      This program is for showing data type on PHP, There is no need to define data type on PHP.
Its automatic define type to the variable as the value is assign to its.

Example like:
$var2   5;  // type will be string
$var2 =  "5";  // type will be integer

#########################################
PHP Code
#########################################
<?php

$var1  =  "The 2 Sentences";
$var2   5;  // type will be string
$var2 =  "5";  // type will be integer

echo $var1;
echo "<br/>";

echo $var2;
echo "<br/>";

settype($var2,'integer');
echo $total = $var1 + $var2;
echo "<br/>";

echo gettype($var1);
echo "<br/>";
echo gettype($var2);
echo "<br/>";
settype($var2,'integer');
echo gettype($var2);
echo "<br/>";

$var1 = "The first Sentances";
$var2 = "The second Sentances";

echo $var1;
echo "<br/>";

echo $var2;
echo "<br/>";

echo $total = $var1 + $var2;
echo "<br/>";

echo gettype($var1);
echo "<br/>";
echo gettype($var2);
echo "<br/>";

// Check the variable type

// check the variable is array or not
if(is_array($var1))
{
echo "Its an Array.";
} else {
echo "Its not an Array.";
}
// check the variable is array or not

echo "<br/>";

// check the variable is float or not
if(is_float($var1))
{
echo "Its an Float.";
} else {
echo "Its not an Float.";
}
// check the variable is float or not

echo "<br/>";

// check the variable is bool or not
if(is_bool($var1))
{
echo "Its an bool.";
} else {
echo "Its not an bool.";
}
// check the variable is bool or not

echo "<br/>";

// check the variable is integer or not
if(is_int($var1))
{
echo "Its an integer.";
} else {
echo "Its not an integer.";
}
// check the variable is integer or not

echo "<br/>";

// check the variable is NULL or not
if(is_null($var1))
{
echo "Its an NULL.";
} else {
echo "Its not an NULL.";
}
// check the variable is NULL or not

echo "<br/>";

// check the variable is numeric or not
if(is_numeric($var1))
{
echo "Its an numeric.";
} else {
echo "Its not an numeric.";
}
// check the variable is numeric or not

echo "<br/>";

// check the variable is string or not
if(is_string($var1))
{
echo "Its an string.";
} else {
echo "Its not an string.";
}
// check the variable is string or not

echo "<br/>";
?>

Comments

Popular posts from this blog

Page Unload Show Notification to user

Function Oriented File Upload PHP

Upload File Using PHP - Example For Image