Google News
logo
PHP Program to Check if the type of a variable is float
In PHP, you can check the type of a variable using the `gettype()` function, which returns a string indicating the data type of the variable.

To check if a variable is a float, you can use the `is_float()` function, which returns `true` if the variable is a float and `false` otherwise.

Here's an example :
Program :
<?php
    $num = 3.14;
    if (is_float($num)) {
        echo "The variable is a float.";
    } else {
        echo "The variable is not a float.";
    }
?>
Output :
The variable is a float.
In this code, the variable `$num` is assigned the float value `3.14`. The `if` statement checks if `$num` is a float using the `is_float()` function.

If `$num` is a float, then the code inside the `if` block is executed, which simply prints the message "The variable is a float." Otherwise, the code inside the `else` block is executed, which prints the message "The variable is not a float."

This demonstrates how you can use the `is_float()` function to check if a variable is a float in PHP.