When should you use intval() in PHP to secure a string that represents a number?

When you have a string that represents a number and you want to ensure it is securely converted to an integer value, you should use the intval() function in PHP. This function will safely convert the string to an integer, stripping any non-numeric characters and preventing potential security vulnerabilities such as SQL injection attacks.

$numberString = "12345";
$secureNumber = intval($numberString);