I’m very new in PHP, and would like to do a foreach loop that won’t repeat a result if the same item has been output before.
Here’s my code:
foreach ( $attachments as $id => $attachment ) {
echo ($attachment->post_title);
}
As you can see, the word would be pulled by echo ($attachment->post_title);.
Is there a way to do some checking and avoid duplicates?
Many thanks for your help.
1 Answer