PHP intval() Function | What is Intval? Get the integer value of a variable

Summary: in this article, you will learn PHP intval() Function | What is Intval? Get the integer value of a variable? let’s understand in details.

What is PHP Intval?

The intval() function is an inbuilt function in PHP that is used to get the integer value of a variable.

It is an inbuilt function, returns the integer value of a variable. Using the specified base for the conversion, furthermore, it returns the integer value of the variable provided. The default base is 10. It shouldn’t be used on objects else it would return E_NOTICE level error and return 1.

Syntax:

intval(var_name, base)

Parameter Values

This function accepts two parameters out of which one is mandatory while the other one is optional. Parameters are described below:

Name Description Type
var_name It is a mandatory parameter. The scalar value being converted to an integer or Specifies the variable to check. Mixed*
base It is a optional parameter. it specifies the base to use for the conversion. Only has an effect if the variable is a string. The default base is 10. If base is not specified.

  • If var_name contains 0x (or 0X) as prefix, the base is taken as 16.
  • If var_name starts with 0, the base is taken as 8
Integer
.
Important Note: *Mixed: Here, mixed indicates that a parameter may accept multiple types i.e. but not necessarily all

Return value

The integer value of var on success, or 0 on failure

Technical Details

Return Value: The integer value of the variable on success, 0(zero) on failure. furthermore, an empty array will return 0, & a non-empty array will return 1
PHP Changelog: PHP 5.1: When an object is passed to the variable, it throws E_NOTICE and returns 1
Return Type: Integer
PHP Version: 4.0+

PHP intval() Function Example

Example:1

It will return the integer value of different variables:

64
6
64
0
1

Example:2

146
146
146
146
-146
102
4
0
43
146000000
146000000000000000
14
10

Example:3

8

Example:4

20839

Example:5

46
38

Conclusion:PHP intval

In this article, you have learned What is Intval function, and how to Get the integer value of a variable with example. I hope you will enjoy it!. if have any query then contact on info@tutorialscan.com. I will try to resolve the problem.