2013-01-02 32 views
-1

可能重複:
php function variable scopePHP變量VS外

沒有任何理由我不能在功能推這些變量? 如果我這樣做

//function scraping_for_text_2 
for($i=0; $i<$l; $i++) { 
echo "$contents[$i]"; 
echo "$fnamearray[$i].torrent"; 
} 

它返回了正確的vaules

,但是當我有這樣

function scraping_for_text_2($iUrl,$iText) 

$curl = curl_init(); 

curl_setopt($curl, CURLOPT_URL, $uploadurl); 
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30); 
curl_setopt($curl, CURLOPT_VERBOSE, 1); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($curl, CURLOPT_COOKIEFILE, 'cookies.txt'); 
curl_setopt($curl, CURLOPT_POST, true); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); 
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); 
$curlresult = curl_exec($curl); 
curl_close ($curl); 
         $data = array( 

"description" => "testing", 
"torrent" => "@$fnamearray[$i]", 
"submit" => "Upload" 
); 

我得到這個 通知的功能:未定義的變量:fnamearray 注意:未定義的變量:我在

+1

http://php.net/manual/en/language.variables.scope.php – DaveRandom

+1

將它們作爲參數傳遞給你的函數!你也可以通過'globals'或'$ GLOBALS'來訪問它們,但我不會推薦它。 – mpen

+0

它被稱爲[範圍](http://php.net/manual/en/language.variables.scope.php)。這很好。你可以濫用像全球的東西,但不應該。 – ficuscr

回答

4

您可能想要學習基本概念,如在涉及任何編程語言之前,請先閱讀。

在這種情況下,您的變量根本不在函數內部定義。