Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

intval()

Convert an input to an integer, truncating a finite in-range float towards zero.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

intval(mixed $value, int $base = 10): int

Convert an input to an integer, truncating a finite in-range float towards zero. The base selects how string digits are read. Base zero recognizes prefixes such as 0x, and a base argument has no effect on an existing integer. Valid string bases are 0 or 2 through 36. With base 1 or 37 the string "10" yields 0.

Signature

intval(mixed $value, int $base = 10): int

Example output

[-2,2,16,10,0,0,10]

Examples

<?php
echo json_encode([intval(-2.9), intval("10", 2), intval("0x10", 0), intval(10, 2), intval("10",1), intval("10",37), intval(10,37)]);

Result

[-2,2,16,10,0,0,10]

Sources