Jump to content

timeout because of for loop


kirkh34

Recommended Posts

I've been getting this error:

 

Fatal error: Maximum execution time of 30 seconds exceeded in... (gives file and line number)

 

I've cut out most of the code in the for loop to narrow it down specifically to the $i variable messing it up somehow...

The 2nd part of the if statement where I try to append the $i variable to the new $row_ variable is causing it to hang like this. 

I want to be able to make 5 new variables... $row_1...$row_2...etc...  but for some reason when I try to append the $i to it, it hangs. and throws that error eventually.  Does anyone know why it does this? Any help is appreciated. Thank you!

 


for ($i=1;$i<6;$i++){

if ($row['bef_remarks' . $i] !=  "Description"){
$row_.$i = 1;

Link to comment
https://forums.phpfreaks.com/topic/234809-timeout-because-of-for-loop/
Share on other sites

I know you have it figured out, but it was hanging because you'd need to do the concatenation of 'row_' and $i first, then use that value as a variable variable. I'm not sure what the technical reason is without digging into the manual, but that was what I had to do to make it work. I'm sure it has to do with the way the concatenation operator works (or doesn't) on variables without assigning the result to a new variable . . .

 

for ( $i=1; $i < 6; $i++ ) {
   if ($row["bef_remarks{$i}"] !=  "Description"){
      $var = "row_$i";
      $$var = 1;
   }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.