What is better and why:

is_int('12345'); 

or

 filter_var('12345', FILTER_VALIDATE_INT); 

?

    1 answer 1

    Somewhat strange question. These are different functions and they perform different actions. It is enough to look into the documentation to make sure of this and understand that they should not be compared. It's like "what's better echo or var_dump ?". And this and that displays something on the screen.

    I will describe what the is_int () function does . It returns TRUE if the argument passed to it is INT and FALSE if not INT.

    The filter_var function returns the filtered value. In your example, it will return not TRUE but 12345. This is very important to understand and this is a very big difference.

    • Thanks, I didn’t know - I usually skim through the documentation. More like to experience the functions in practice, to understand their mechanism of action. - nick777
    • Download the PHP directory in chm, everything is there, a very convenient thing, and the newcomer, the more it should be! - Gena Ant