php7的foreach遍历数组,PHP中使⽤foreach遍历三维数组昨天写代码的时候遇到⼀个三维数组,突然不知道怎么遍历这个三维数组,后⾯经过研究才发现,三维数组可以使⽤双foreach遍历,现在就分享给⼤家。
PHP代码:
//⾸先声明⼀个三维数组或者⾃⼰从数据库⾥查询
$list=array(
"user"=>array(
array(1,"AA",20,"woman"),
array(2,"BB",20,"woman"),
array(3,"CC",25,"man")
),
"score"=>array(
array(1,100,98,95,96),
array(2,56,98,87,84),
array(3,68,75,84,79)
),
"connect"=>array(
array(1,'content1',"AA@haoshu888"),
array(2,'content2',"BB@haoshu888"),
array(3,'content3',"CC@haoshu888")
)
);
//循环遍历
foreach($list as $key=>$value){
echo "
echo "
".$key."
";//以每个数组的键值作为表名
foreach($value as $val){
echo "
";
foreach($val as $v){
echo "
".$v."";php8兼容php7吗
}
echo "
";
}
echo "
";
}
>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。