Example of multi-dimensional array foreach traversal in PHP. Copy the code as follows :? Php declares a three-dimensional array $ infoarray (userarray (array (1, zhangsan, 20, nan), array (2, lisi, 20, nan), array (3, wangwu, 25, nv), scorea
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"
";
}
?>
The http://www.bkjia.com/PHPjc/802223.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/802223.htmlTechArticle code is as follows :? Php // declare a 3D array $ info = array ("user" = array (1, "zhangsan", 20, "nan"), array (2, "lisi", 20, "nan"), array (3, "wangwu", 25, "nv"), "score" =...