How can PHP be used to determine which forum threads a user has not read or where a new post has been created?

To determine which forum threads a user has not read or where a new post has been created, you can store the last read post ID for each user in a database table. Then, compare this ID with the latest post ID in each thread to identify unread threads or new posts.

// Assuming $lastReadPostId is the last post ID read by the user
// Connect to database and retrieve latest post ID in each thread
// Compare $lastReadPostId with the latest post ID to determine unread threads or new posts

// Example code snippet to retrieve latest post ID in each thread
$threadIds = [1, 2, 3]; // Array of thread IDs
foreach ($threadIds as $threadId) {
    $latestPostId = // Retrieve latest post ID in thread $threadId from database
    if ($latestPostId > $lastReadPostId) {
        echo "New post in thread $threadId\n";
    } else {
        echo "Unread posts in thread $threadId\n";
    }
}