遍歷某個數組時 當該數組中嵌套數組,怎么獲取內層數組元素中的某一個鍵值?
<?php
?$students = array(
'2010'=>array('令狐沖',"59"),
'2011'=>array('林平之',"44"),
'2012'=>array('曲洋',"89"),
'2013'=>array('任盈盈',"92")
}
?>我只要序號和成績??怎么遍歷獲取
<?php
?$students = array(
'2010'=>array('令狐沖',"59"),
'2011'=>array('林平之',"44"),
'2012'=>array('曲洋',"89"),
'2013'=>array('任盈盈',"92")
}
?>我只要序號和成績??怎么遍歷獲取
2017-01-03
舉報
2017-01-03
這個問題需要通過數組的索引來訪問第二個參數,
<?php
$students = array(
'2010'=>array('令狐沖',"59"),
'2011'=>array('林平之',"44"),
'2012'=>array('曲洋',"89"),
'2013'=>array('任盈盈',"92"),
);
foreach( $students as $key=>$value)
{
? ? echo '學號為'.$key.'的同學成績為';
? ? echo $value[1];//只要第二項,索引為1。
? ? echo "<br/>";
}
?>