PHP doubleval() Function
The PHP doubleval() function returns the float value of a variable. This function is an alias of floatval() function.
Syntax
doubleval(variable)
Parameters
variable |
Required. Specify the variable whose corresponding float value will be returned. Must be a scalar type. |
Return Value
Returns the float value of the given variable. Empty arrays return 0, non-empty arrays return 1.
Strings will most likely return 0 although this depends on the leftmost characters of the string. If the string is numeric or leading numeric then it will resolve to the corresponding float value, otherwise it is converted to 0.
Note: If an object is passed to this function, it throws an E_NOTICE level error and returns 1.
Example:
The example below shows the usage of doubleval() function.
<?php $x = "1234.56789"; echo doubleval($x)."\n"; $y = "1234.56789Hello"; echo doubleval($y)."\n"; $z = "Hello1234.56789"; echo doubleval($z)."\n"; $a = "12345E-3"; echo doubleval($a)."\n"; $b = "12345E3"; echo doubleval($b)."\n"; ?>
The output of the above code will be:
1234.56789 1234.56789 0 12.345 12345000
Example:
Consider one more example which demonstrates the use of this function with arrays.
<?php $arr1 = array(); echo doubleval($arr1)."\n"; $arr2 = array(1, 2, 3); echo doubleval($arr2)."\n"; ?>
The output of the above code will be:
0 1
❮ PHP Variable Handling Reference