【发布时间】:2011-05-30 12:57:07
【问题描述】:
我目前正在用 PHP 中的数组进行试验,并创建了一个假环境来显示团队的信息。
$t1 = array (
"basicInfo" => array (
"The Sineps",
"December 25, 2010",
"lemonpole"
),
"overallRecord" => array (0, 0, 0, 0),
"overallSeasons" => array (
1 => array (14, 0, 0),
2 => array (9, 5, 2),
3 => array (12, 4, 0),
4 => array (3, 11, 2)
),
"games" => array (
"<img src=\"images/cs.gif\" alt=\"Counter-Strike\" />",
"<img src=\"images/cs.gif\" alt=\"Counter-Strike\" />",
"<img src=\"images/cs.gif\" alt=\"Counter-Strike\" />",
"<img src=\"images/cs.gif\" alt=\"Counter-Strike\" />"
),
"seasonHistory" => array (
"Season I",
"Season II",
"Season III",
"Season IV"
),
"divisions" => array (
"Open",
"Main",
"Main",
"Invite"
)
);
// Displays the seasons the team has been in along
// with the record of each season.
function seasonHistory() {
// Make array variable local-scope.
global $t1;
// Count the number of seasons.
$numrows = count($t1["seasonHistory"]);
// Loop through all the variables until
// it reaches the last entry made and display
// each item seperately.
for($v = 0; $v <= $numrows; $v++) {
// Echo each season.
echo "<tr><td>{$t1["games"][$v]}</td>";
echo "<td>{$t1["seasonHistory"][$v]}</td>";
echo "<td>{$t1["divisions"][$v]}</td></tr>";
}
}
我已经测试了几个可能的问题,在缩小范围后我得出了一个结论,那就是我的函数由于某种原因没有连接到数组。我不知道还能做什么,因为我认为使数组全局化可以解决这个问题。
什么有效:
我可以在我需要它显示的页面上回显 $t1["games"][0],它会为我提供内容。
我尝试了 echo $t1["games"][0] INSIDE 函数,然后调用该函数,它没有显示任何内容。
【问题讨论】:
标签: php arrays user-defined-functions