How can I limit the code below to show 10 loops.
foreach( $entries as $entry ) {
echo '<tr>';
$fields = wpforms_decode( $entry->fields );
foreach( $fields as $field ) {
if ( in_array( $field['id'], $ids)) {
echo '<td>' . apply_filters( 'wpforms_html_field_value', wp_strip_all_tags( $field['value'] ), $field, $form_data, 'entry-frontend-table' );
}
}
echo '</tr>';
}
One possibility where the loop to break is the first one:
foreach( $entries as $key=>$entry )
{
if($key==9) break;
echo '<tr>';
$fields = wpforms_decode( $entry->fields );
foreach( $fields as $field )
{
if ( in_array( $field['id'], $ids))
{
echo '<td>' . apply_filters( 'wpforms_html_field_value', wp_strip_all_tags( $field['value'] ), $field, $form_data, 'entry-frontend-table' );
}
}
echo '</tr>';
}
Another possiblity where the loop to break is the second one:
foreach( $entries as $entry )
{
echo '<tr>';
$fields = wpforms_decode( $entry->fields );
foreach( $fields as $key=>$field )
{
if($key==9) break;
if ( in_array( $field['id'], $ids))
{
echo '<td>' . apply_filters( 'wpforms_html_field_value', wp_strip_all_tags( $field['value'] ), $field, $form_data, 'entry-frontend-table' );
}
}
echo '</tr>';
}
If you want to stop the whole process / method / function you might want to use return instead of break. Break will just stop the current loop process.
like this :
$i = 0;
foreach( $entries as $entry ) {
$i++;
if ($i > 9 ) break; // this will stop after the 10th loop and in the beginning of loop 11
echo '<tr>';
$fields = wpforms_decode( $entry->fields );
foreach( $fields as $field ) {
// if you want to stop this loop too use $ii not $i
// but notice stopping this loop will not stop the parent loop !
if ( in_array( $field['id'], $ids)) {
echo '<td>' . apply_filters( 'wpforms_html_field_value', wp_strip_all_tags( $field['value'] ), $field, $form_data, 'entry-frontend-table' );
}
}
echo '</tr>';
}