How to Check if String is a Integer in PHP?

03-Apr-2023

.

Admin

How to Check if String is a Integer in PHP?

Hi Dev,

Now, let's see tutorial of how to check if string is a integer in php?. you will learn how do you know if a string is int or double?. We will use is string a number php?. I explained simply about how check string is value int or not in php?.

There are example to Check if String Contains check string contains integer in PHP. in this example, we will use to is_int() function to check string contains integer. so Let's the following example with output.

Example 1


index.php

<?php

$values = array(23, "23", 23.5, "23.5", null, true, false);

foreach ($values as $value) {

echo "is_int(";

var_export($value);

echo ") = ";

var_dump(is_int($value));

}

?>

Output:

is_int(23) = bool(true)

is_int('23') = bool(false)

is_int(23.5) = bool(false)

is_int('23.5') = bool(false)

is_int(NULL) = bool(false)

is_int(true) = bool(false)

is_int(false) = bool(false)

I hope it could help you...

#PHP