Phco Posted July 16, 2019 Share Posted July 16, 2019 (edited) Hello, I have some php-files containing variables with same names but different data. $arr = array("file1.php", "file2.php", "file3.php"); I want to "get access" to these variables/data. One php-file at a time. This is what i am doing right now: for($i=0; $i<sizeof($arr); $i++) include $arr[$i]; This does work in the first 2 php-files in the array but not on any other of them unless i change start-value of $i. Could you maybe help me solve this? Edited July 16, 2019 by cyberRobot added code tags / removed text background Quote Link to comment Share on other sites More sharing options...
chhorn Posted July 16, 2019 Share Posted July 16, 2019 (edited) what should "does [not] work" mean? i would recommend using foreach if you don't need a continious integer. Edited July 16, 2019 by chhorn Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted July 16, 2019 Share Posted July 16, 2019 Need more info. What is it supposed to do, what is it not doing. I 2nd foreach. $files = array("file1.php","file2.php","file3.php"); foreach($files as $file) { include($file); } Quote Link to comment Share on other sites More sharing options...
ginerjm Posted July 16, 2019 Share Posted July 16, 2019 What do you mean by "have same variables but different data"? You do realize that one variable will replace any previously defined variable by the same name so having multiple uses of a single var name is not going to work? 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.