Mahngiel Posted March 13, 2012 Share Posted March 13, 2012 // in this case, $teams_count = 16 for($j = $tournament->teams_count; $j != 1; $j/2) { echo $j; } What I expect: 16 | 8 | 4 | 2 | 1 What I get: memory exhaustion. PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 128716801 bytes) Is it so late, I'm missing something? Quote Link to comment https://forums.phpfreaks.com/topic/258807-simple-for-exhausting-memory/ Share on other sites More sharing options...
Mahngiel Posted March 13, 2012 Author Share Posted March 13, 2012 If you are interested, I solved my own problem by ditching a for() and adding a while() while($tournament->team_count >= 1) { for($j = 1; $tournament->team_count >= 1;$j++) { echo '<div id="round_' . $j . '">'; for($i = 1; $i <= $tournament->team_count; $i++) { echo '<div class="tourney_cell">Player ' . $i . '</div>'; } echo '</div>'; $tournament->team_count = $tournament->team_count / 2; } } Quote Link to comment https://forums.phpfreaks.com/topic/258807-simple-for-exhausting-memory/#findComment-1326720 Share on other sites More sharing options...
xyph Posted March 13, 2012 Share Posted March 13, 2012 That while loop is redundant. It's not the while loop that fixed it, it's the change of $!= to >= Quote Link to comment https://forums.phpfreaks.com/topic/258807-simple-for-exhausting-memory/#findComment-1326721 Share on other sites More sharing options...
Mahngiel Posted March 13, 2012 Author Share Posted March 13, 2012 That while loop is redundant. It's not the while loop that fixed it, it's the change of $!= to >= Actually, not wholly correct. The while loop was redundant, but the issue lies in expression 3 and the fact that i never changed the stored value of $j. // original loop for($j = $tournament->teams_count; $j != 1; $j/2) // fixed loop for($j = $tournament->teams_count; $j != 1; $j= $j/2) Quote Link to comment https://forums.phpfreaks.com/topic/258807-simple-for-exhausting-memory/#findComment-1326797 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.