Only show first image in foreach loop

Depending of what you are exactly trying to achieve accessing the first element of the $posts array may work for you. No need for the foreach loop.

echo '<img src="'.$posts[0]['img']['url'].'">';