Hello,
What version and license of phpdocx are you using?
Anyway, the code is working with the data you are adding. You are replacing all placeholders (with the same name):
$docx->replaceVariableByHtml('dynamic', 'block', $item);
with the same value. If you need to replace only the first one, you need to use the firstMatch option:
foreach ($datas as $key => $item) {
$docx->replaceVariableByHtml('dynamic', 'block', $item, array('firstMatch' => true));
}
Using this option you can iterate an array, the first placeholder of the template is replaced, then the second one (as the first placeholder doesn't exist, this second placeholder is now the first occurrence) and so on.
Regards.