What are best practices for formatting and posting PHP code in forums for troubleshooting purposes?

When posting PHP code in forums for troubleshooting purposes, it is important to format it properly for readability. Use code formatting tools like markdown or code blocks to make the code stand out. Additionally, ensure that the code snippet is complete and includes any necessary dependencies or variables for it to work properly. Finally, provide a brief explanation of the code snippet and how it addresses the issue at hand. For example: Issue: How to properly sanitize user input in PHP to prevent SQL injection attacks.

// Sanitize user input to prevent SQL injection
$user_input = $_POST['user_input'];
$sanitized_input = mysqli_real_escape_string($connection, $user_input);