dad00 Posted December 9, 2009 Share Posted December 9, 2009 Hi, I keep getting this error Fatal error: Out of memory (allocated 72876032) (tried to allocate 35 bytes) in ****/spinner.php on line 12 heres the loop that im using $offset=0; $i=1; $position2=0; $continue=true; $splitted[1]= 1; do{ $offset=$position2 + 1; $splitted[$i]=$offset; // LINE 12 HERE <---- if (in_array($offset, $splitted, true)) { $continue=false; }else{ $position1= stripos($_POST['text'],"{",$offset); $position2= stripos($_POST['text'],"}",$offset); $position3= $position2 - $position1; $split = substr($_POST['text'], $position1, $position3); $split = substr($split, 1); $splitted[$i]=$offset; echo $i." ".$split."<br>".$offsetlog[$i]."<br> <br>"; } $i++; }while ($continue=true); I know it probably isnt very well coded, but does anyone know how to solve my error? Link to comment https://forums.phpfreaks.com/topic/184550-out-of-memory/ Share on other sites More sharing options...
ToonMariner Posted December 9, 2009 Share Posted December 9, 2009 it looks like you have an infinite loop there matey... the conditional the breaks the loop is probably never evaluating as true. Link to comment https://forums.phpfreaks.com/topic/184550-out-of-memory/#findComment-974296 Share on other sites More sharing options...
dad00 Posted December 9, 2009 Author Share Posted December 9, 2009 yeah, but i cant work out where in the code it is going wrong. i cant see any problems :S Link to comment https://forums.phpfreaks.com/topic/184550-out-of-memory/#findComment-974297 Share on other sites More sharing options...
mrMarcus Posted December 9, 2009 Share Posted December 9, 2009 just add a break: if (in_array($offset, $splitted, true)) { $continue=false; break; } Link to comment https://forums.phpfreaks.com/topic/184550-out-of-memory/#findComment-974306 Share on other sites More sharing options...
dad00 Posted December 9, 2009 Author Share Posted December 9, 2009 yay, it works now. thanks! Link to comment https://forums.phpfreaks.com/topic/184550-out-of-memory/#findComment-974309 Share on other sites More sharing options...
mrMarcus Posted December 9, 2009 Share Posted December 9, 2009 problem is, you don't know how do-while works. the reason your code is bumming out is because with a do-while, the do{} always executes one time no matter the condition (while()). therefore, your code was executing that one time regardless of the conditions, then coming back and looping again, now with $i having incremented to 2 making your if (in_array($offset, $splitted, true)) { $continue=false; } return false (as a function), causing the forever loop as $offset will then never find itself in $splitted, since every value of $splitted array is 1, always, forever, never changes. EDIT: i think. i may have just confused myself. but unless you're comfortable with do-while loops, just use a simple while/for/foreach. Link to comment https://forums.phpfreaks.com/topic/184550-out-of-memory/#findComment-974314 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.