65 of 110 menu

PHP Integer

Checking for an Integer

Checking for an integer is done using the function is_int:

<?php $num = 1234; $res = is_int($num); ?>

It returns either true or false.

An integer can be a string. The is_int function will output false in this case. For such a check, use is_numeric:

<?php var_dump(is_numeric('1234')); // will output true ?>

Converting to an Integer

Like this:

<?php $str = '1234'; $num = (int) $str; ?>

Or like this:

<?php $str = '1234'; $num = (integer) $str; ?>

Or like this:

<?php $str = '1234'; $num = intval($str); ?>
English
БеларускаяEspañolРусский
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline