输出数组
<html>
<meta charset='utf-8'>
</html>
<?php
$student = array(
1901 => array(
'name' => "AJEST",
'age ' => "24",
'sex' => "男",
'grade' => "79.9"
),
1902 => array(
'name' => "MDM",
'age ' => "23",
'sex' => "女",
'grade' => "59.9"
),
1903 => array(
'name' => "XL",
'age ' => "25",
'sex' => "男",
'grade' => "59.9"
),
);
//print_r($student);
foreach($student as $keya => $valuea){
echo $keya;
foreach($valuea as $keyb => $valuesb){
echo $valuesb;
};
echo "<br />";
}
?>
运行结果
表格输出
<html>
<meta charset='utf-8'>
</html>
<?php
$table="<table border='1' cellpadding='0' cellspacing='0' width='80%'>";
$student = array(
1901 => array(
'name' => "AJEST",
'age ' => "24",
'sex' => true,
'grade' => "79.9"
),
1902 => array(
'name' => "MDM",
'age ' => "23",
'sex' => false,
'grade' => "59.9"
),
1903 => array(
'name' => "XL",
'age ' => "25",
'sex' => true,
'grade' => "59.9"
),
);
$table="<table border='1' cellpadding='0' cellspacing='0' width='50%'>";
$table.="<tr>";
$table.="<td>姓名</td>";
$table.="<td>年龄</td>";
$table.="<td>性别</td>";
$table.="<td>成绩</td>";
$table.="</tr>";
foreach($student as $keya ){
$table.="<tr>";
foreach($keya as $keyb ){
if ($keyb === true){
$keyb = "男";
}
if ($keyb === false){
$keyb = "女";
}
$table.="<td>$keyb</td>";
}
$table.="</tr>";
}
$table.="</table>";
echo $table;
?>
运行结果
完整表格输出
<html>
<meta charset='utf-8'>
</html>
<?php
$table="<table border='1' cellpadding='0' cellspacing='0' width='80%'>";
$student = array(
1901 => array(
'name' => "AJEST",
'age ' => "24",
'sex' => true,
'grade' => "79.9"
),
1902 => array(
'name' => "MDM",
'age ' => "23",
'sex' => false,
'grade' => "59.9"
),
1903 => array(
'name' => "XL",
'age ' => "25",
'sex' => true,
'grade' => "59.9"
),
);
$table="<table border='1' cellpadding='0' cellspacing='0' width='50%'>";
$table.="<tr>";
$table.="<td>学号</td>";
$table.="<td>姓名</td>";
$table.="<td>年龄</td>";
$table.="<td>性别</td>";
$table.="<td>成绩</td>";
$table.="</tr>";
foreach($student as $keya => $valuesa ){
$table.="<tr>";
$table.="<td>$keya</td>";
foreach($valuesa as $keyb => $valuesb ){
if ($valuesb === true){
$valuesb = "男";
}
if ($valuesb === false){
$valuesb = "女";
}
$table.="<td>$valuesb</td>";
}
$table.="</tr>";
}
$table.="</table>";
echo $table;
?>
运行结果
愿你
历经山河 仍觉人间值得
历经千帆 归来仍是少年
笑得坦荡 眼里都是太阳
此生尽兴 赤忱善良
以梦为马 不负韶华