sgraeber Posted December 2, 2008 Share Posted December 2, 2008 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 More sharing options...
awpti Posted December 2, 2008 Share Posted December 2, 2008 Try these: ini_set('memory_limit', '512M'); Or in your .htaccess: php_value memory_limit 512M Otherwise there's not much you can do short of partial reads/writes until you've looped through it. Link to comment https://forums.phpfreaks.com/topic/135171-loop-array-out-of-memory/#findComment-704056 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.