I'm trying to understand the difference between while and for each. Both of these examples will work it seems like the only real difference is preference. Perhaps it is in this case but are their situations when one is objectively better than the other?
<?php $rows = get_field('repeater_field_name');
if($rows)
{
echo '<ul>';
foreach($rows as $row)
{
echo '<li>sub_field_1 = ' . $row['sub_field_1'] . ', sub_field_2 = ' . $row['sub_field_2'] .', etc</li>';
}
echo '</ul>';
} ?>
VS.
<?php if( have_rows('repeater_field_name') ): ?>
<ul>
<?php while( have_rows('repeater_field_name') ): the_row(); ?>
<li><?php the_sub_field('sub_field_1'); ?>,<?php the_sub_field('sub_field_1'); ?>, etc</li>
<?php endwhile; ?>
</ul>