나는 어떤 상수와 방법을 가지고 config.php
파일이 있습니다.
config.php
에있는 방법 중 하나를 호출하는 test.php
파일이 있습니다.
관련 코드는 다음과 같습니다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 출력 제품입니다. 누구도이 신비한 행동에 대해 어떤 생각을 가지고 있습니까?
당신이 $ 정의하는 질문을해야합니다? 포함하는 파일 또는 호출 스크립트에서? 포함에 정의 된 경우 PrintAnswersOnMe()를 호출 할 때 범위를 벗어난 것 같습니다. – ernie
변수가 함수의 범위 밖에 있습니다. http://php.net/manual/en/language.variables.scope.php 추가 읽기 – pbond
님, PHP 지식을 좀 배워주세요. http://www.php.net/manual/en/language.variables.scope.php – CBroe