thomashw Posted May 1, 2008 Share Posted May 1, 2008 I keep getting a "Maximum execution time of 30 seconds exceeded..." on the first line of this code. The $optionvalue array has two values in it. for ( $j = 0; $j <= count( $optionvalue ) - 2; $j + 2 ) { $name = $optionvalue[ $j ]; $price = $optionvalue [ $j + 1 ]; $options[ $name ] = $price; } Link to comment https://forums.phpfreaks.com/topic/103667-help-with-for-loop/ Share on other sites More sharing options...
blackcell Posted May 1, 2008 Share Posted May 1, 2008 It looks like your loop is chasing itself to end. Where are you pulling the array option value from? Link to comment https://forums.phpfreaks.com/topic/103667-help-with-for-loop/#findComment-530827 Share on other sites More sharing options...
thomashw Posted May 1, 2008 Author Share Posted May 1, 2008 It's being populated before the for loop. I printed it and it was populated fine. I figured out the problem. I had to put $j += 2 instead of $j + 2. Is that normal? Link to comment https://forums.phpfreaks.com/topic/103667-help-with-for-loop/#findComment-530829 Share on other sites More sharing options...
mrdamien Posted May 1, 2008 Share Posted May 1, 2008 Yeah that's normal. You need to change the value of $j to reach the end. $j + 2 doesn't change it. Link to comment https://forums.phpfreaks.com/topic/103667-help-with-for-loop/#findComment-530830 Share on other sites More sharing options...
pocobueno1388 Posted May 1, 2008 Share Posted May 1, 2008 I think what your meaning to do is: for ( $j = 0; $j <= count( $optionvalue ) - 2; $j += 2 ) Link to comment https://forums.phpfreaks.com/topic/103667-help-with-for-loop/#findComment-530831 Share on other sites More sharing options...
thomashw Posted May 1, 2008 Author Share Posted May 1, 2008 Woops. I guess I'm so used to using something like $j++ I didn't even think about it. That was dumb of me. Link to comment https://forums.phpfreaks.com/topic/103667-help-with-for-loop/#findComment-530833 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.