我以为我理解php数组,但似乎我没有:(
这是我的代码:
<?php
// Create a magazines array
$magazines = array();
// Put 5 magazines on it
for($x=0;$x<5;$x++)
$magazines[] = "Magazine " . $x ;
// Associate articles array to each magazine
foreach($magazines as $magazine){
$articles[$magazine] = array();
for($x=0;$x<3;$x++)
$articles[$magazine] = $magazine . " - Article " . $x ;
}
// List them all
foreach($magazines as $magazine){
echo $magazine . " has these articles: <br>";
foreach($articles[$magazine] as $article)
echo $article . "</br>";
}
?>
它只打印杂志,而不是每个杂志内的文章.很明显,我对嵌套的foreach循环有一些看法.请你帮助我好吗?我究竟做错了什么?提前致谢!