I want to make it so that every 3 columns it forms a new row. I am lost and can’t figure out how to do this even after reading other posts.So I’d want it to be like
icon icon icon
icon icon icon
icon icon icon
etc….
foreach($sMenu as $row) {
$sClass = ($row['id'] == $aPage['id']) ? ' class="ui-btn-active ui-btn-custom"' : ' class="ui-btn-custom"';
$sIcon = ($row['icon'] != '') ? ' data-icon="' . $row['icon'] . '"' : '';
$sSiteRoot = get('site-root');
$row['url'] .= ($row['url'] == '') ? '' : '/';
$url = $sSiteRoot . $row['url'];
$url = str_replace('(', '%28', $url);
$url = str_replace(')', '%29', $url);
$url = str_replace("'", '%27', $url);
$sNavigation2 .= '<td><img src=". $sIcon .' . $url . '"></td>';
}
Sometimes the easiest way to do this is to have a variable keep track of how many times you run this loop. For example:
Then, inside of the loop, just check to see if the number
$iis equal to 2 (in this case.)Then, just keep going through the foreach loop.
This can also be done using the modulus operator as a cleaner way to write this “row break” check (as shown by the other answers here.)