php怎么循环输出二维数组,PHP中遍历二维数组—以不同形式的输出操作
//定義二維索引數(shù)組
$arr = array(
array("101","李軍","男","1976-02-20","95033"),
array("103","陸君","男","1974-06-03","95031"),
array("105","匡明","男","1975-10-02","95031"),
array("107","王麗","女","1976-01-23","95033"),
array("108","曾華","男","1977-08-01","95033"),
array("109","王芳","女","1975-02-10","95031")
);
第一種輸出形式(echo語句)
/* echo "
echo "
SnoSnameSsexSbirthdayClass";foreach($arr as $v){
echo "
{$v[0]}{$v[1]}{$v[2]}{$v[3]}{$v[4]}";}
echo "
" ;第二種輸出形式(HTML代碼 表格輸出)
| Sno | Sname | Ssex | Sbirthday | Class |
foreach($arr as $v){
echo "
{$v[0]}{$v[1]}{$v[2]}{$v[3]}{$v[4]}";};
?>
第三種輸出形式(下拉列表)
$arr = array(
array("1","山東"),
array("2","北京"),
array("3","上海"),
array("4","廣州"),
array("5","香港"),
array("6","澳門")
);
?>
請選擇
foreach($arr as $v){
echo "$v[1]";
};
?>
第四種輸出形式
取數(shù)組中輸出的總數(shù)
$arr = array(
array(4)
);
echo $arr[0][0];
取數(shù)組中一組數(shù)據(jù)
$arr = array(
array("1","上海")
);
echo "{$arr[0][1]}";
取數(shù)組中任意一個數(shù)據(jù)
$arr = array(
array("1","臺灣"),
array("2","北京"),
array("3","上海"),
array("4","廣州"),
array("5","香港")
);
echo "{$arr[4][1]}";
?>
內(nèi)容來源于網(wǎng)絡(luò)如有侵權(quán)請私信刪除
總結(jié)
以上是生活随笔為你收集整理的php怎么循环输出二维数组,PHP中遍历二维数组—以不同形式的输出操作的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java链表list_java自定义Li
- 下一篇: date日期相减 java_一个小小的J