我正在修改一个用于以列表格式输出每周课程表的 wordpress 小部件。就像现在的代码一样,它将输出每个工作日,然后是当天的班级信息。问题是即使有一天没有课,它仍然会呼应那一天的名字。我想跳过回显任何不包含其数组中数据的 $weekday 。这是代码:
<?php
/**
* @file
* Output view template.
*
* Available Variables:
* - $weekday_names: Array of weekday names to be used in table output.
* - $weekdays: Array of used weekdays based on user preference.
* - $start_hours: Array of unique start hours.
* - $classes: Multi-dimensional array in the structure of $classes[weekday][start_hour].
*/
?>
<div id="wcs-schedule-list">
<?php foreach ( $weekdays as $weekday ): ?>
<h3><?php echo $weekday; ?></h3>
<div class="list-container">
<ul class="wcs-schedule-list">
<?php foreach ( $start_hours as $start_hour ): ?>
<?php echo WcsSchedule::model()->renderListItem( $classes, $start_hour, $weekday ) ?>
<?php endforeach; ?>
</ul>
</div>
<?php endforeach; ?>
</div>
任何帮助将不胜感激!
这是var_dump($start_hours);
一个空的 $weekday。
Tuesday
array(6) { [1]=> string(8) "12:00 pm" [6]=> string(7) "2:00 pm" [4]=> string(7) "3:30 pm" [5]=> string(7) "6:00 pm" [2]=> string(7) "7:00 pm" [0]=> string(7) "8:15 pm" } array(6) { [1]=> string(8) "12:00 pm" [6]=> string(7) "2:00 pm" [4]=> string(7) "3:30 pm" [5]=> string(7) "6:00 pm" [2]=> string(7) "7:00 pm" [0]=> string(7) "8:15 pm" } array(6) { [1]=> string(8) "12:00 pm" [6]=> string(7) "2:00 pm" [4]=> string(7) "3:30 pm" [5]=> string(7) "6:00 pm" [2]=> string(7) "7:00 pm" [0]=> string(7) "8:15 pm" } array(6) { [1]=> string(8) "12:00 pm" [6]=> string(7) "2:00 pm" [4]=> string(7) "3:30 pm" [5]=> string(7) "6:00 pm" [2]=> string(7) "7:00 pm" [0]=> string(7) "8:15 pm" } array(6) { [1]=> string(8) "12:00 pm" [6]=> string(7) "2:00 pm" [4]=> string(7) "3:30 pm" [5]=> string(7) "6:00 pm" [2]=> string(7) "7:00 pm" [0]=> string(7) "8:15 pm" } array(6) { [1]=> string(8) "12:00 pm" [6]=> string(7) "2:00 pm" [4]=> string(7) "3:30 pm" [5]=> string(7) "6:00 pm" [2]=> string(7) "7:00 pm" [0]=> string(7) "8:15 pm" }