Translate

Monday, May 5, 2014

4.Function Testing on Variable

is_null():

function is_null () return true if Variable Worth null or not assign a value.
For example:
<?php
 $x;<br> 
if (is_null(@$x))
   echo "True Condition";
 else
   echo "False Condition";
?>
Result
True Condition

is_integer():

function is_integer return true if Variable value Integer.
For example:
<?php
 $x = 10;
 if (is_integer($x))
   echo "True Condition";
 else
   echo "False Condition";
?>
Result
True Condition

is_bool():

function is_bool () return true if Variable value as a Boolean.
For example:
<?php
 $x = true;
 if (is_bool($x))
   echo "True Condition";
 else
   echo "False Condition";
?>
Result
True Condition

is_string():

function is_string () return true if Variable value as a String.
For example:
<?php
  $x = "This is string";
  if (is_string($x))
    echo "True Condition";
  else
    echo "False Condition";
?>
Result
True Condition

is_double() or is_float() or is_real():

The above three function have the same role it return true if Variable Data fractions.
For example:
<?php
$x = 10;
if (is_double($x))
   echo "True Condition";
else
   echo "False Condition";
?>
Result
False Condition

is_array():

function is_array () return true if Variable Array.
For example:
<?php
$x = 20;
if (is_array($x))
 echo "True Condition";
else
 echo "False Condition";
?>
Result
False Condition

empty():

function empty() return true if Variable value as "" , '' , false , null ,Not exist or has not assign value.
For example:
<?php
 $x = '';<br> if(empty($x))
   echo "True Condition";
 else
   echo "False Condition";
?>
Result
True Condition

isset():

function isset () return true if Variable $ x occurs. Its not really like null yet exist.
For example:
<?php
 $x = 12;
 if (isset($x))
   echo "True Condition";
 else
   echo "False Condition";
?>
Result
True Condition

unset():

function unset () serves Clear the value contained in the Variable from Memory.
For example:
<?php
  $x = 12;
  unset($x);
  echo @$x; // output : nothing because $x is now null
?>

is_numeric():

function is_numeric () return true if $ x is a number or a String.
For example:
<?php
 $x = “12”;
 if (is_numeric($x))
   echo "True Condition";
 else
   echo "False Condition";
?>
Result
True Condition


0 comments:

Post a Comment