大神們求解答
<?php
?$students = array(
'2010'=>array('令狐沖',"59"),
'2011'=>array('林平之',"44"),
'2012'=>array('曲洋',"89"),
'2013'=>array('任盈盈',"92"),
'2014'=>array('向問(wèn)天',"93"),
'2015'=>array('任我行',"87"),
'2016'=>array('沖虛',"58"),
'2017'=>array('方正',"74"),
'2018'=>array('岳不群',"91"),
'2019'=>array('寧中則',"90"),
);//10個(gè)學(xué)生的學(xué)號(hào)、姓名、分?jǐn)?shù),用數(shù)組存儲(chǔ)
?
foreach($students as $key=>$val)
{ //使用循環(huán)結(jié)構(gòu)遍歷數(shù)組,獲取學(xué)號(hào)?
? ? ?echo $key; //輸出學(xué)號(hào)
echo ":";
//循環(huán)輸出姓名和分?jǐn)?shù)
foreach($val as $v)
{
echo $v;?
}
echo "<br />";
}
?>
請(qǐng)問(wèn)里面的$key $students $v $val都代表著什么?是根據(jù)什么定義的名字
2018-04-20
$students代表一個(gè)數(shù)組,$key是數(shù)組的鍵,$val是鍵對(duì)應(yīng)的另一個(gè)數(shù)組,$v是$val數(shù)組對(duì)應(yīng)的值,以上都是針對(duì)上面的代碼而言,簡(jiǎn)單來(lái)說(shuō),這四個(gè)都是變量,根據(jù)變量的命名規(guī)范來(lái)定義的,只要符合命名規(guī)范,你可以用任何字符代替他們