将二维数组用foreach遍历并以表格的形式输出

//声明一个不是完整对齐格式的二维数组
        $group=[
"GroupName"=>"第二组",
"GroupPrice"=>"$987",
                 ["name"=>"经理","sex"=>"man","age"=>28,"email"=>"[email protected]"],
                 ["name"=>"ZS","sex"=>"woman","age"=>30,"email"=>"[email protected]"],
                 ["name"=>"LS","sex"=>"man","age"=>34,"email"=>"[email protected]"],
                 ["name"=>"WW","sex"=>"man","age"=>34,"email"=>"[email protected]"],
                 ["name"=>"ZL","sex"=>"man","age"=>34,"email"=>"[email protected]"],
                 ["name"=>"SQ","sex"=>"woman","age"=>34,"email"=>"[email protected]"],
                 ["name"=>"FB","sex"=>"man","age"=>34,"email"=>"[email protected]"],
                 ["name"=>"QJ","sex"=>"woman","age"=>34,"email"=>"[email protected]"],
                 ["name"=>"AS","sex"=>"man","age"=>34,"email"=>"[email protected]"],
                ];


echo '';
echo '';
echo '';
echo '';
echo '';
echo '';
echo '';
echo '';
foreach($group as $kk=>$row)
{
//判断数组中的值是否还是为数组,如果是则遍历出值放入单个表格中
if(is_array($row))
{
echo '';
foreach($row as $col)
{

echo "";
}
}
//如果不是数组则原样输出
else
{
echo '';
echo "";
echo '';
}
echo '';
}
echo '

将数组转化为表格的形式输出

namesexageemail
{$col}
{$kk}:{$row}
';
?>

你可能感兴趣的:(PHP地基,小程序)