This article mainly introduces the foreach traversal of multi-dimensional arrays in PHP. For more information, see
This article mainly introduces the foreach traversal of multi-dimensional arrays in PHP. For more information, see
The Code is as follows:
// Declare a 3D Array
$ Info = array (
"User" => array (
Array (1, "zhangsan", 20, "nan "),
Array (2, "lisi", 20, "nan "),
Array (3, "wangwu", 25, "nv ")
),
"Score" => array (
Array (1,100, 95, 96 ),
Array (, 84 ),
Array (3,68, 75,84, 79)
),
"Connect" => array (
Array (1, '20140901', "salkh@bbs.com "),
Array (2, '20140901', "aikdki@sina.com "),
Array (3, '20140901', "42816@qq.com ")
)
);
// Cyclically traverse and output a table
Foreach ($ info as $ tableName => $ table ){
Echo"
";Echo"
". $ TableName ."
"; // Use the key value of each array as the table nameForeach ($ table as $ row ){Echo"
";Foreach ($ row as $ col ){Echo"
". $ Col ." | ";}Echo"
";}Echo"
";
}
?>
,