Tables array =
$tables = array(
'Delta'=> array('Available','1','2'),
'Alpha' => array('Available','2','4'),
'Bravo'=> array('Available','2','4'),
'Charlie' => array('Available','4','6'),
'Echo' => array('Available','4','6')
);
单位数组 -
$units = array (
'00:00' => '1' ,
'00:15' => '2' ,
'00:30' => '3' ,
'01:00' => '4' ,
'01:15' => '5' ,
...tl/dr
echo "<table>";
while( $tab = each( $tables ) )
{
echo "<tr>";
echo "<td>".$tab[ 'key' ]."</td>";
while( $element = each( $units ) )
{
echo "<td class='free'>".$element['key']."</td>";
}
echo "</tr>";
}
echo "</table>";
目前的结果:
Delta 12:00 12:15 12:30 12:45 13:00 13:15 13:30 13:45 .... 阿尔法
布拉沃
查理
回声
答案 0 :(得分:3)
您的代码的简单答案是reset()
$units
的数组指针,因为外循环$units
的第一次迭代将被迭代并到达结尾:
while( $tab = each( $tables ) )
{
echo "<tr>";
echo "<td>".$tab[ 'key' ]."</td>";
reset($units);
while( $element = each( $units ) )
{
echo "<td class='free'>".$element['key']."</td>";
}
echo "</tr>";
}
但是foreach()
会为您执行此操作:
foreach( $tables as $tab )
{
echo "<tr>";
echo "<td>".$tab[ 'key' ]."</td>";
foreach( $units as $element )
{
echo "<td class='free'>".$element['key']."</td>";
}
echo "</tr>";
}