PHP floatval() Function

PHP floatval() Function

The floatval() function in PHP is used to give the float value of a variable.

Syntax

floatval ( mixed $var )

Parameter

var(required)- This parameter represents the name of the variable that is to be converted.

Return

This function returns the float value of the given variable.

If the var is initialized with empty arrays, it returns 0 else for non-empty arrays it returns 1. The strings will most likely return 0 although this depends on the leftmost characters of the string.

Example 1

 

Output

The variable: 417.209mln
After the floatval() function
New Variable: 417.209 

Example 2

 

Output

The variable: The417.209mln
After the floatval() function
New Variable: 0 

Example 3

 

Output

The variable: 
After the floatval() function
New Variable: 0 

Example 4

 

Output

The variable: !@#$%
After the floatval() function
New Variable: 0 

Example 5

 

Output

The variable: 123.00000001
After the floatval() function
New Variable: 123.00000001 

Related Topics

PHP $ and $$ Variables

PHP $var variable is a normal variable that stores any value. PHP $$var variable is a reference variable that stores the value of$var inside it. Let us take an example. Example 1 <?php $x =...

1 minute read.

PHP Do While Loop

PHP do while loop is used to execute the code at least one time because condition is checked after executing the code. Syntax: do{ //code to be executed  }while(condition); Output <?php $n=1;  do{ echo "$n<br/>";  $n++;  }while($n<=5);  ?> Output 1 2 3 4 5 ← Prev Next →...

1 minute read.

PHP str_getcsv() Function

PHP str_getcsv() Function The str_getcsv() function in PHP parses a CSV string into an array and returns an array containing the fields read. Syntax str_getcsv ( string $input [, string $delimiter [, string $enclosure [, string$escape ]]] ) Parameter input(required)- This parameter represents the string to parse. delimiter(optional)- This parameter signifies...

1 minute read.

PHP lcfirst() Function

PHP lcfirst() Function The lcfirst() function in PHP converts the first character of a string to lowercase if that character is alphabetic. Syntax lcfirst ( string $str ) Parameter str(required)- This parameter signifies the input string. Return This function returns a string with the...

1 minute read.

PHP in_array() Function

PHP in_array() Function The in_array() function in PHP checks if the value exists in the specified array or not. Syntax in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )  Parameter needle(required)- This parameter represents the searched value. haystack(required)- This parameter represents the input array. strict(optional)- This parameter...

1 minute read.

PHP print_r() Function

PHP print_r() Function The print_r() function in PHP displays the information stored in a variable. Syntax print_r (mixed $expression [, bool $return] ) Parameter expression(required)- This parameter represents the expression to be printed. return(optional)- This parameter is used to store the output of...

2 minutes read.

PHP range() Function

PHP range() Function The range () function in PHP is used to create an array containing a range of elements. Syntax range ( mixed $start , mixed $end [, number $step = 1 ] ) Parameter start(required)- This parameter represents the first value of the sequence. end(required)- This parameter represents the...

1 minute read.

PHP array_combine() Function

PHP array_combine() Function The array_combine() function in PHP is used to create an array by combining two arrays i.e., one array for keys and another array for its values. Syntax array_combine ( array $keys , array $values ) Parameter keys(required)- This parameter represents an array which acts...

1 minute read.

PHP uksort() Function

PHP uksort() Function The uksort() function in PHP sorts an array by keys using a user-defined comparison function. Syntax uksort ( array &$array , callable $key_compare_func ) Parameter array(required)- This parameter represents the input array. key_compare_func(required)- This parameter represents a string that describe a callable comparison function....

1 minute read.

PHP number_format() Function

PHP number_format() Function The number_format() function in PHP formats a number with grouped thousands. This function accepts one, two, or four parameters (not three): Syntax number_format ( float $number [, int $decimals ] )             or number_format ( float $number , int $decimals  , string $dec_point, string$thousands_sep ) Parameter number(required)- This parameter represents the number to be formatted. If...

1 minute read.

PHP array_multisort() Function

PHP array_multisort () Function The array_multisort() function in PHP sorts multiple or multi-dimensional arrays at once. Syntax array_multisort ( array &$array1 [, mixed $array1_sort_order [, mixed $array1_sort_flags [, mixed $... ]]] ) Parameter array1(required)- This parameter specified the input array to sort. array1_sort_order(optional)- This parameter specifies the order (ascending or descending)...

1 minute read.

PHP Indexed Array

In PHP, arrays are linear data structures that allow to store multiple elements of the same type under a single variable which helps in saving the time and effort of...

3 minutes read.

PHP quoted_printable_decode() Function

PHP quoted_printable_decode() Function The quote_printable_decode() function of PHP converts a quoted-printable string to an 8 bit string. It works similar to imap_qprint(), except this one does not require the IMAP module to work. Syntax quoted_printable_decode ( string $str ) Parameter str(required)- This parameter represents the...

1 minute read.

PHP Magic Constants

There are various predefine PHP Magic Constants. It starts with underscore(__) and ends with double underscore.  Magic Constant Description __LINE__ To check current line number of the file. __FILE__ To check full path and filename of...

1 minute read.

PHP quoted_printable_encode() Function

PHP quoted_printable_encode() Function The quoted_printable_encode() function in PHP converts a 8 bit string to a quoted-printable string. This function is similar to imap_8bit(), except this one does not require the IMAP module to work. Syntax quoted_printable_encode ( string $str ) Parameter str(required)- This parameter represents...

1 minute read.

PHP Date and Time

DATE: The PHP date() function formats a date or time. The timestamp is used to format a more readable date and time into a PHP date () function. Syntax: date(format,timestamp) Simple Date: Characters that...

1 minute read.

PHP printf() Function

PHP printf() Function The printf() function in PHP outputs a formatted string. The related functions of printf() function are as follows: sprintf()vprintf()vsprintf()fprintf()vfprintf() Syntax printf ( string $format [, mixed $... ] )  Parameter format(required)- This parameter formats the string which is composed of zero or...

1 minute read.

PHP Continue

What is continue in PHP? Inside the loop, the continue statement is used to control the loop in preprocessor hypertext. PHP utilizes the continue keyword to implement the continue statement, which...

3 minutes read.

PHP stripos() Function

PHP stripos() Function The stripos() function in PHP finds the position of the first occurrence of a substring in the specified string. It is a case-insensitive a binary-safe function. The related functions are as follows: strripos() Functionstrpos() Functionstrrpos() Function Syntax stripos ( string $haystack , mixed $needle [, int $offset...

1 minute read.

PHP strspn() Function

PHP strspn() Function The strspn() function of PHP finds the length of the initial segment of string that contains only characters from the mask parameter. Syntax strspn(string$subject,string$mask[,int$start[,int$length]] ) Parameter subject(required)- This parameter represents the input string. mask(required)- This parameter specifies the characters to find. start (optional)- It signifies the position in the string to start...

1 minute read.