我正在取消你的计划,并提出我将如何做,希望它能帮助你。
首先获取以下格式的数据:
$movies = array (
array (
'title' => 'Babies',
'times' => array(
1286460000,1286467200,1286476200,1286487000
)
),
array (
'title' => 'El secreto de sus ojos',
'times' => array(
1286474400,1286481600,1286483400
)
)
// more movies...
);
以下是工作代码的链接:
http://ideone.com/P4zZn
这是密码
<?php
date_default_timezone_set('GMT');
$start_hour = 12; // Start hour of matrix
$end_hour = 22; // End hour of matrix
$skip_hours = array( 18, 20 );
// Get the timestamp for each hour in the matrix
foreach( range( $start_hour, $end_hour ) as $hr ) {
if ( in_array( $hr, $skip_hours ) ) {
continue;
}
$time_sections[] = mktime( $hr,0,0, 10, 7, 2010 ); // You'll want to put null or the month/day to use the current month/day
}
$movies = array (
array (
'title' => 'Babies',
'times' => array(
1286460000,1286467200,1286476200,1286487000
)
),
array (
'title' => 'El secreto de sus ojos',
'times' => array(
1286474400,1286481600,1286483400
)
)
);
?>
<table border="1">
<thead>
<th>Movie</th>
<?php foreach( $time_sections as $time_section ): ?>
<th><?php echo date( 'G:i', $time_section ) ?> </th>
<?php endforeach; ?>
</thead>
<tbody>
<?php foreach( $movies as $movie ): ?>
<tr>
<td><?php echo $movie['title'] ?></td>
<?php foreach( $time_sections as $time_section_index => $time_section ): ?>
<td>
<!-- while there are movie times left and the first movie time in the array is less than the next timestamp print the movie time -->
<?php while( count( $movie['times'] ) && current( $movie['times'] ) < $time_sections[$time_section_index + 1] ): ?>
<!-- echo the time and pull it from the array -->
<?php echo date( 'G:i', array_shift( $movie['times'] ) ) ?>
<?php endwhile; ?>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>