You are building your array and iterating over it at each iteration of the outer Loop. Think about what happens.
First iteration of the outer loop
$get_year
becomes array('2012')
and you iterate over it echo
ing “2012”.
Second iteration
$get_year
becomes array('2012',2013')
and you iterate over it echo
ing “2012” and “2013”.
Do you see what happened? You have echo
ed the same data twice. You are echo
ing the partially constructed $get_year
array. The more posts you have the bigger the problem will become and I would not be surprised if it crashed the browser eventually.
Pull that foreach
out of the other loop so that you only iterate over it once– after it is has been completely constructed.
$loop = new WP_Query($args);
while($loop->have_posts()) {
$loop->the_post();
$get_year[] = get_the_time('Y');
}
foreach($get_year as $year) {
echo $year;
}
wp_reset_postdata();