The goal is to loop through an array of days-of-the-week (array values are stored as strings, eg: 'Mon, Tues, Weds', etc) and output some HTML when today's day is encountered.
The file is a CMS's .tpl file, so the PHP sits directly alongside the HTML.
My current, working code is:
<?php $dayofweek = date('w'); foreach ($dataarray['openingDays'] as $day_key => $opening_day): $i++; //if $i is equal to 7 make it 0 to match array $i = ($i == 7 ? 0 : $i); //If today's date matches $i if ($dayofweek == $i): ?> <div class="todays-date"> <?php else: ?> <div class="not-todays-date"> <?php endif; print $opening_day; ?> </div> <?php endforeach; ?>
This is one of the first times I've used ternary and would like to know if it is done correctly. I am also concerned about not initializing
$i and would like to know if that is acceptable.