Jump to content

Out of memory


dad00

Recommended Posts

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

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

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.