PHPWord addListItem 循环破坏文档

PHPWord addListItem loop corrupts the document

$cInc = json_decode($inc);

$c = count((array)$cInc);

for ($x = 0; $x < $c; $x++)
{
    $section->addListItem($cInc[$x]);
}

所以我想将数组 $cInc 循环到一个列表项,但循环以某种方式破坏了文档。

我认为你使用 count

是错误的

count()函数returns数组中元素的个数

所以你不需要数组 inside count

$cInc = json_decode($inc);

$c = count($cInc);

for ($x = 0; $x < $c; $x++)
{
    $section->addListItem($cInc[$x]);
}

或者如果你不知道你有多少个数组,你可以使用 foreach

$cInc = json_decode($inc);

foreach ($cInc as $val)
{
    $section->addListItem($val);
}