Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

is_numeric()

Recognize numbers and numeric strings before numeric processing.

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

Syntax

is_numeric(mixed $value): bool

Recognize numbers and numeric strings before numeric processing. In PHP 8 an otherwise numeric string may have leading and trailing ASCII whitespace. Exponents are accepted. Hexadecimal text and a numeric prefix followed by units fail the check.

Signature

is_numeric(mixed $value): bool

Example output

[true,true,false,false,true]

Examples

<?php
echo json_encode(array_map("is_numeric", [" 2 ", "1e3", "0xff", "2kg", 3]));

Result

[true,true,false,false,true]

Sources