X
    Categories: PHP

Examining variable types in PHP

In PHP, there are a range of built-in functions which you can call to check variable types.  They return a Boolean value  – true if the variable is of that type and false if it is not.

To check if a variable contains a string, you can use the is_string function. You can use it like that:

echo var_dump(is_string("DQDQ")); // true



echo var_dump(is_string(23)); // false



echo var_dump(is_string("11")); // true

You should be aware that a number within a string (for example, coming from user input) is still a string and not a number when checking the variable type.

To check whether a variable is an integer, you can use the is_int function.

Ivan Dimov: Ivan is a student of IT, a freelance web designer/developer and a tech writer. He deals with both front-end and back-end stuff. Whenever he is not in front of an Internet-enabled device he is probably reading a book or traveling. You can find more about him at: http://www.dimoff.biz. facebook, twitter