如何使用foreach循环打印“名称”和“ ID”?如何打印特定的列详细信息?
试图抓住钥匙
$student[0]="Subject";
$student[1]=" Marks<br>";
$student["Subject"]="English ";
$student["Marks"]=56;
foreach($student as $item)
echo $item;
$arr=array("first"=>array("Name"=>"ABC","ID"=>45),
"second"=>array("Name"=>"XYZ","ID"=>56)
);
foreach($arr as $element=>$key)
{
echo"<br>$element"
foreach($key as $header)
echo" $header";
}
输出-
Subject Marks
English 56
first ABC 45
second XYZ 56
答案 0 :(得分:0)
您快完成了。只是缺少此foreach上的内循环键值
$arr = array(
"first" => array("Name" => "ABC", "ID" => 45),
"second" => array("Name" => "XYZ", "ID" => 56),
);
foreach($arr as $element=>$key)
{
foreach($key as $header_k => $header){
echo"$element $header_k $header <br>";
}
}