How can PHP code be optimized to ensure that integer values are only passed to input fields if they contain content?

When passing integer values to input fields in PHP, it's important to ensure that only non-empty integer values are passed. This can be achieved by checking if the integer value is not empty before assigning it to the input field.

// Check if the integer value is not empty before passing it to the input field
$integerValue = isset($_POST['integer_value']) && $_POST['integer_value'] !== '' ? (int)$_POST['integer_value'] : '';

// Assign the integer value to the input field
<input type="text" name="integer_value" value="<?php echo $integerValue; ?>">