Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

is_scalar()

Accept values of type bool, int, float or string.

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

Syntax

is_scalar(mixed $value): bool

Accept values of type bool, int, float or string. Empty strings and false are scalar as well. Null, arrays and objects fail; this predicate establishes a type category and says nothing about whether the value is empty.

Signature

is_scalar(mixed $value): bool

Example output

[true,true,true,true,false,false,false]

Examples

<?php
echo json_encode(array_map("is_scalar", [false, 0, 1.5, "", null, [], new stdClass()]));

Result

[true,true,true,true,false,false,false]

Sources