PHP intval() Function

❮ PHP Variable Handling Reference

Example

Return the integer value of different variables:

<?php
$a = 32;
echo intval($a) . "<br>";

$b = 3.2;
echo intval($b) . "<br>";

$c = "32.5";
echo intval($c) . "<br>";

$d = array();
echo intval($d) . "<br>";

$e = array("red", "green", "blue");
echo intval($e) . "<br>";
?>
Try it Yourself »

Definition and Usage

The intval() function returns the integer value of a variable.


Syntax

intval(variable, base);

Parameter Values

Parameter Description
variable Required. Specifies the variable to check
base Optional. Specifies the base to use for the conversion. Only has effect if variable is a string. Default base is 10

Technical Details

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

❮ PHP Variable Handling Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.