Page 1 of 1
Require function with for
Posted: Mon Jul 11, 2005 10:54 am
by mustafamisir
Hi,
I used this part of code;
Code: Select all
for($i = 0; $i < 5; $i++)
{
$id = $tempї$i];
require('file.php');
}
But this code finish after one turn, how Ican solve this problem?
Posted: Mon Jul 11, 2005 11:10 am
by Deemo
most likely in file.php, you use the variable $i and it throws off the parent loop. Try setting it to $index rather than $i and see if it works
Posted: Mon Jul 11, 2005 12:02 pm
by hawleyjr
From the manual :)
http://us2.php.net/manual/en/function.require.php
Code: Select all
Similarly, looping structures do not affect the behaviour of require().
Although the code contained in the target file is still subject to the loop,
the require() itself happens only once.
Posted: Mon Jul 11, 2005 12:35 pm
by onion2k
Using include() instead should solve the problem of it being loaded once.
Posted: Mon Jul 11, 2005 12:37 pm
by John Cartwright
require_once(), include_once() is a more appropriate way of dealing with loops I think.