MySQL can return unique records or you can get PHP to sort through the results, I think it's usually better to get MySQL to do most of the work.
PHP Code:
<?php
//0002 has three posts, 0764 has two posts.
$thread_posts_ids = array("0002","0024","0014","0002","0764","8888","0764","4321","0002","7632");
$thread_posts_unique_ids = array_unique($thread_posts_ids);
foreach ($thread_posts_unique_ids as $value){
echo "Send email to: $value<br>";
}
?>
Output
Code:
Send email to: 0002
Send email to: 0024
Send email to: 0014
Send email to: 0764
Send email to: 8888
Send email to: 4321
Send email to: 7632