To avoid memory problems, when creating a dynamic function within loops, register it as a global variable, and check if it has already been set;
<?php
global $my_func;
if (!isset($my_func))
{
$my_func = create_function($args, $code);
}
$my_func();
?>
That way you don't end up creating the same function twice (or a couple of million of times, as it happened to me...)