What are the best practices for posting code snippets in PHP forums for troubleshooting purposes?

When posting code snippets in PHP forums for troubleshooting purposes, it is important to clearly explain the issue or how to solve it in a concise manner. This helps other forum members understand the context of the code snippet. For example: Issue: How to validate an email address in PHP Code snippet:

$email = "test@example.com";
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
    echo "Valid email address";
} else {
    echo "Invalid email address";
}