frame

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Register

PHP Numbers

PHP Numbers

Check if the type of a variable is integer

<!DOCTYPE html>
<html>
<body>

<?php
// Check if the type of a variable is integer  
$x = 5985;
var_dump(is_int($x));

echo "<br>";

// Check again... 
$x = 59.85;
var_dump(is_int($x));
?>  

</body>
</html>

Check if the type of a variable is float

<!DOCTYPE html>
<html>
<body>


<?php
// Check if the type of a variable is float 
$x = 10.365;
var_dump(is_float($x));
?>  


</body>
</html>


Check if a numeric value is finite or infinite

<!DOCTYPE html>
<html>
<body>


<?php
// Check if a numeric value is finite or infinite 
$x = 1.9e411;
var_dump($x);
?>  


</body>
</html>


Invalid calculation will return a NaN value

<!DOCTYPE html>
<html>
<body>


<?php
// Invalid calculation will return a NaN value
$x = acos(8);
var_dump($x);
?>  


</body>
</html>


Check if a variable is numeric

<!DOCTYPE html>
<html>
<body>


<?php
// Check if the variable is numeric   
$x = 5985;
var_dump(is_numeric($x));


echo "<br>";


$x = "5985";
var_dump(is_numeric($x));


echo "<br>";


$x = "59.85" + 100;
var_dump(is_numeric($x));


echo "<br>";


$x = "Hello";
var_dump(is_numeric($x));
?>  


</body>
</html>

Cast float and string to integer<!DOCTYPE html><html>

<body>


<?php
// Cast float to int 
$x = 23465.768;
$int_cast = (int)$x;
echo $int_cast;
  
echo "<br>";


// Cast string to int
$x = "23465.768";
$int_cast = (int)$x;
echo $int_cast;
?>  


</body>
</html>
Tagged:
Sign In or Register to comment.

Developer

| make vanilla clean and light
@ 2016 Your Sitename, All rights reserved. Material Design is a design language developed by Google. Material Design makes more liberal use of grid-based layouts and responsive animations and transitions.
Powered by VanillaForums, Designed by ThemeSteam

Contact us

info@example.com
support@example.com
(800) 3032120

Get In Touch