-1

Possible Duplicate:
php function variable scope

is there any reason i can't push these variables in the function? if i do this

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

it echoes back the correct vaules

but when i have an function like this

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"
);

i get this Notice: Undefined variable: fnamearray Notice: Undefined variable: i in

3
  • 1
    php.net/manual/en/language.variables.scope.php Commented Jan 2, 2013 at 22:10
  • 1
    pass them as arguments into your function! you can also access them via the globals or $GLOBALS but i wouldn't recommend it. Commented Jan 2, 2013 at 22:10
  • It is called scope. It is good. You can abuse it with things like global's but should not. Commented Jan 2, 2013 at 22:11

1 Answer 1

4

You might want to learn basic concepts such as variable scoping before getting too involved in any programming language.

In this case, your variables simply aren't defined inside the function.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.