批改状态:合格
老师批语:
效果图:

代码:
<?php
echo '<hr color="green">';
echo '<h2>用for循环来实现关联数组的遍历</h2>';
$reporter = ['baranch' => '三总支','department' => '手术室', 'title' => '冬日送温暖' ,'name'=>'张三' ,'number'=>'30'];
// for ($i=0; $i <count($reporter); $i++) {
// echo key($reporter),'=>',current($reporter),'<br>';
// next($reporter);
// }
echo '<table border="1" cellpadding="3" cellspacing="0" width="400">';
echo '<caption>稿费统计</caption>';
echo '<tr bgcolor="lightblue" align="center"><td>总支名称</td><td>科室</td><td>题目</td><td>作者</td><td>用稿情况</td></tr>';
echo '<tr>';
for ($i=0; $i <count($reporter) ; $i++) {
echo '<td align="center">'.current($reporter).'</td>';
next($reporter);
}
echo '</tr>';
echo '</table>';
echo '<hr color="green">';
echo '<h2>用while()循环来实现关联数组的遍历</h2>';
$reporter = ['baranch' => '三总支','department' => '手术室', 'title' => '冬日送温暖' ,'name'=>'张三' ,'number'=>'30'];
echo '<table border="1" cellpadding="3" cellspacing="0" width="400">';
echo '<caption>稿费统计</caption>';
echo '<tr bgcolor="lightblue" align="center"><td>总支名称</td><td>科室</td><td>题目</td><td>作者</td><td>用稿情况</td></tr>';
echo '<tr>';
$i=0;
while ( $i <count($reporter)) {
echo '<td align="center">'.current($reporter).'</td>';
next($reporter);
$i++;
}
echo '</tr>';
echo '</table>';
echo '<hr color="green">';
echo '<h2>用foreach循环来实现关联数组的遍历</h2>';
$reporter = ['baranch' => '三总支','department' => '手术室', 'title' => '冬日送温暖' ,'name'=>'张三' ,'number'=>'30'];
echo '<table border="1" cellpadding="3" cellspacing="0" width="400">';
echo '<caption>稿费统计</caption>';
echo '<tr bgcolor="lightblue" align="center"><td>总支名称</td><td>科室</td><td>题目</td><td>作者</td><td>用稿情况</td></tr>';
echo '<tr>';
foreach ($reporter as $value) {
echo '<td align="center">'.$value.'</td>';
}
echo '</tr>';
echo '</table>';
echo '<hr color="green">';
?>点击 "运行实例" 按钮查看在线实例
手抄:

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号