Jump to content

loop array: out of memory?


sgraeber

Recommended Posts

Hello,

 

 

I recently run into a problem with looping through a big array.

 

I have an array $bodyContent->children() with several thousand entries. I intent to loop through them and see if there are any matching tags. (Those tags that match should be excluded in the end).

 

But I always run into an Out-Of-Memory message ("Allowed memory size of 33554432 bytes exhausted").

 

Anyone ideas how to improve my code. (Unfortunately I cannot increase memory size in php.ini)

 

 

Here's my code:

 

 

$length = count($bodyContent->children());

for ( $i = 0; $i <= $length; $i++) {
if ($bodyContent->children($i)->tag == 'table' || $bodyContent->children($i)->tag == 'ul' || $bodyContent->children($i)->tag == 'ol') {
	// do nothing here
}
else {
			$content .= $bodyContent->children($i);
}
}

 

I really appreciate all your help! Thanks alot!

Link to comment
https://forums.phpfreaks.com/topic/135171-loop-array-out-of-memory/
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.