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. Link to comment https://forums.phpfreaks.com/topic/115924-solved-passing-array-to-a-function/ Share on other sites More sharing options...
trq Posted July 21, 2008 Share Posted July 21, 2008 That should work as expected. Link to comment https://forums.phpfreaks.com/topic/115924-solved-passing-array-to-a-function/#findComment-596008 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. Link to comment https://forums.phpfreaks.com/topic/115924-solved-passing-array-to-a-function/#findComment-596011 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. Link to comment https://forums.phpfreaks.com/topic/115924-solved-passing-array-to-a-function/#findComment-596013 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 ? Link to comment https://forums.phpfreaks.com/topic/115924-solved-passing-array-to-a-function/#findComment-596015 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. Link to comment https://forums.phpfreaks.com/topic/115924-solved-passing-array-to-a-function/#findComment-596018 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. Link to comment https://forums.phpfreaks.com/topic/115924-solved-passing-array-to-a-function/#findComment-596019 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.