Jarid Posted August 10, 2010 Share Posted August 10, 2010 Here is a section of php file A include_once(dirname(__FILE__) . '/PhpfileB.php') $VALID_RATING_IDS = $Ratethese Here is all of php file B $Ratethese = "array("1", "2",);" I need the var $VALID_RATING_IDS to = $Ratethese from file B I am trying to include an array from php file B in php file A. Is this possible? How can i accomplish this? Link to comment https://forums.phpfreaks.com/topic/210384-how-can-i-include-an-array-from-another-php-file/ Share on other sites More sharing options...
freeloader Posted August 10, 2010 Share Posted August 10, 2010 Once you included file B into file A, both of them are 'joined' together. Php will treat it like one big file. So yes, you should be able to just call upon the array in file B. Link to comment https://forums.phpfreaks.com/topic/210384-how-can-i-include-an-array-from-another-php-file/#findComment-1097836 Share on other sites More sharing options...
linus72982 Posted August 10, 2010 Share Posted August 10, 2010 I think you'll need to include: global $Ratethese; in your first file before you assign. Or maybe not, who knows, I've never been good at encapsulation and scope. Link to comment https://forums.phpfreaks.com/topic/210384-how-can-i-include-an-array-from-another-php-file/#findComment-1097842 Share on other sites More sharing options...
Jarid Posted August 11, 2010 Author Share Posted August 11, 2010 PhP File A include_once(dirname(__FILE__) . '/PhpFileB.php'); global $Ratethese; $VALID_RATING_IDS = $RATETHESE; Php File B $RATETHESE = "array("1", "2");" For some reason it is printing the array on the page, and the array is not being used to run the script. Did i do anything wrong? Link to comment https://forums.phpfreaks.com/topic/210384-how-can-i-include-an-array-from-another-php-file/#findComment-1097857 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.