OM2 Posted May 29, 2008 Share Posted May 29, 2008 1. Can I use include anywhere? I want to take out code in the middle of the page... and stick it into a separate file. And just use include to include the code where the code was previously. Is this OK to do? Or should include statements be at the top of the page only? 2. What's the deal with global variables? I declare a variable. i can't access it from within a function: so I have to use global $varname; in the function. I read on php.net that using global variables is bad practice and can lead to hard to track bugs. And if possible, to use arrays instead. Even if I use an array, how do I access the global variable(s)? Pass the array in as a parameter? I can't see how that makes it less prone to bugs? Thanks. OM Link to comment https://forums.phpfreaks.com/topic/107837-newbie-php-questions-can-i-use-include-anywhere-using-global-variables/ Share on other sites More sharing options...
jonsjava Posted May 29, 2008 Share Posted May 29, 2008 yes, you can do that, but I wouldn't exactly call that a global. it's just an include. Remember to add the "<?php" and "?>" in the file most common usage: <?php //code here include("include_file.php"); //code here ?> Link to comment https://forums.phpfreaks.com/topic/107837-newbie-php-questions-can-i-use-include-anywhere-using-global-variables/#findComment-552792 Share on other sites More sharing options...
OM2 Posted May 29, 2008 Author Share Posted May 29, 2008 thanks for that. u answered the first part of my question only. i numbered them 1 and 2. let me know if u can let me know what u think of 2. Link to comment https://forums.phpfreaks.com/topic/107837-newbie-php-questions-can-i-use-include-anywhere-using-global-variables/#findComment-552828 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.