benphelps Posted July 21, 2008 Share Posted July 21, 2008 I need help passing an array into a function. here is an example function test_function($array){ echo $array["testz"]; } $array = array( "testz" => "test", "testa" => "test", "testb" => "test" ); test_function($array); When I try this i get a blank array. Not sure why. Quote Link to comment Share on other sites More sharing options...
trq Posted July 21, 2008 Share Posted July 21, 2008 That should work as expected. Quote Link to comment Share on other sites More sharing options...
benphelps Posted July 21, 2008 Author Share Posted July 21, 2008 Can I pass an array the server made? function test_function($array){ echo $array["uploaded_file"]["name"]; } test_function($_FILES["uploaded_file"]); where $_FILES["uploaded_file"] is the result of a file upload form. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted July 21, 2008 Share Posted July 21, 2008 yes but you don't have to. $_FILES has global scope so its available anywhere within your code. Quote Link to comment Share on other sites More sharing options...
benphelps Posted July 21, 2008 Author Share Posted July 21, 2008 Even if the function that needs $_FILES is an include into the file that will use the function ? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted July 21, 2008 Share Posted July 21, 2008 yes - its a super global - like $_POST, $_GET, $_COOKIE, $_SERVER, $_SESSION - all super globals and are available ANYWHERE within your code. Quote Link to comment Share on other sites More sharing options...
benphelps Posted July 21, 2008 Author Share Posted July 21, 2008 I didn't know that, much thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.