我有一个config.php
文件,里面有一些常量和方法
我有一个test.php
文件,可以调用config.php
中的一种方法
相关代码是:
$Questions = array(
1 => "Is he/she nice?1",
2 => "Is he/she sweet?2",
3 => "Is he/she nice?3",
4 => "Is he/she sweet?4",
5 => "Is he/she nice?5",
6 => "Is he/she sweet?6",
7 => "Is he/she nice?7",
8 => "Is he/she sweet?8",
9 => "Is he/she nice?9",
10 => "Is he/she sweet?10"
);
function PrintAnswersOnMe($uid)
{
$uid = antiSQLi($uid);
$query = "SELECT * FROM AnsAns WHERE fid='".$uid."'";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
$rrr = $row[2];
echo $Questions[1];
echo $rrr . ' ' . $Questions[$rrr];
echo "You'r friend <img src='http://graph.facebook.com/".$row['uid']."/picture/' /> answered " . (($row['answer'] == 1) ? "yes" : "no") . " about wether you're ". $rrr.": " . $Questions[$rrr];
echo "<br /> " . $Questions['2'] . "<br/>";
}
}
test
文件仅调用PrintAnswersOnMe
。 (包括它)
一切工作文件,否 $Question[...]
评估实际HTML输出的激励!
为了检查这一点,我添加了$Questions[2]
- 以及$Questions['2']
- 并且没有一个产生HTML输出。循环确实执行,因为其他一切都是HTML
有趣的是,test.php
内部确实有效 - echo $Questions[...]
实际上是HTML输出的产品。有没有人对这种神秘行为有任何想法?
答案 0 :(得分:2)
function PrintAnswersOnMe($uid, $questions) {
//Code goes here
}
然后你就可以访问了
答案 1 :(得分:1)
您需要在global $Questions;
之前将$uid = antiSQLi($uid);
添加到函数的开头。