is_nanCHECKS if a given
FINDS whether a value is not a number
This function returns a BOOLEAN value when it tests the following variable types:
STRING, NUMERIC, BOOLEAN, ARRAY, NULL, RESOURCE or OBJECT.
This functions returns TRUE wheather $var is a NOT A NUMBER or FALSE if not.
To visualize the result, in this tutorial, we use var_dump associated with an if loop structure as a conditional evaluation framework.
<?php
bool is_nan ( $var )
where,
$var = The value to be checked
?>
EXERCISE
<?php
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The is_nan function accepts
only float NUMBER as a parameter.
If this is not taken into account,
an error warning will be issued.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
$a = acos(3);
if (is_nan($a) == TRUE)
{
var_dump($a);
echo '<br>Variable is NOT a NUMBER!<br><br>';
}
else
{
var_dump($a);
echo '<br>Variable is a NUMBER!<br><br>';
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$b = M_E;
if (is_nan($b) == TRUE)
{
var_dump($b);
echo '<br>Variable is NOT a NUMBER!<br><br>';
}
else
{
var_dump($b);
echo '<br>Variable is a NUMBER!<br><br>';
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$c = 1.6e-19;
if (is_nan($c) == TRUE)
{
var_dump($c);
echo '<br>Variable is NOT a NUMBER!<br><br>';
}
else
{
var_dump($c);
echo '<br>Variable is a NUMBER!<br><br>';
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$d = [ 2, 4, 6 ];
if (is_nan($d) == TRUE)
{
var_dump($d);
echo '<br>Variable is NOT a NUMBER!<br><br>';
}
else
{
var_dump($d);
echo '<br>Variable is a NUMBER!<br><br>';
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
?>