PHP Validation Functions Tutorial

Notes:

PHP Validation Functions:
- allow us to test or validate; whether a given data value is of type integer, double etc.
where:
data value can be a literal, variable name or constant name

is_integer(data value):bool
- checks whether the data value is of type integer

is_double(data value):bool
- checks whether the data value is of type double

is_numeric(data value):bool
- checks whether the data value is of type integer or double

is_bool(data value):bool
- checks whether the data value is of type boolean

is_string(data value):bool
- checks whether the data value is of type string

is_array(data value):bool
- checks whether the data value is of type array

is_object(data value):bool
- checks whether the data value is of type object

is_null(data value):bool
- checks whether the data value is of type NULL

is_resource(data value):bool
- checks whether the data value is of type resource

isset(data value):bool
- checks whether the data value is except NULL

empty(data value):bool
- checks whether the data value is 0, 0.0, "", "0", false, NULL, empty array

Example Code:
<?php

echo (is_integer(4)) ? "yes" : "no";
echo "<br/>";

echo (is_double(4.5)) ? "yes" : "no";
echo "<br/>";

echo (is_numeric(4)) ? "yes" : "no";
echo "<br/>";

echo (is_bool(true)) ? "yes" : "no";
echo "<br/>";

echo (is_string("Manjunath")) ? "yes" : "no";
echo "<br/>";

$names = array("Rama","Ravi");
echo (is_array($names)) ? "yes" : "no";
echo "<br/>";

class Point
{
}
$point1 = new Point();
echo (is_object($point1)) ? "yes" : "no";
echo "<br/>";

$point1 = null;
echo (is_null($point1)) ? "yes" : "no";
echo "<br/>";

$file = fopen("index.php","r");
echo (is_resource($file)) ? "yes" : "no";
echo "<br/>";

$playerScore=10;
echo (isset($playerScore)) ? "yes" : "no";
echo "<br/>";

$playerSpeed=10;
echo (empty($playerSpeed)) ? "yes" : "no";
echo "<br/>";
?>

Interview Questions:

1. PHP stands for ______________
a. Hypertext Preprocessor
b. Preprocessor Hypertext
c. Personal Home Processor
d. Personal Hypertext processor
Ans: a