I do something similar on a site I've developed and don't have any
problems. I don't really see anything here that's problematic, except
that by declaring a new DOMPDF object each call of the loop will
incrementally increase your memory usage. Depending on how complex
your invoices are that can certainly eat up a lot of memory. I would
recommend destroying DOMPDF when you're done with it in the function
with unset($dompdf).
Even so, I don't think you're experiencing a memory error since you're
getting the *last* PDF. If memory were the problem I would think you'd
get the first invoice since you're only getting one. PHP would by
erroring out before any others are generated.
There could be something else going on with the script, but I don't
see the cause in what you posted. Make sure that your file created is
actually unique for each PDF. Is the $filepath echoed for each invoice
and is it different for each one? You might also check to make sure
$site_array isn't being modified somehwere else.
-b