【发布时间】:2018-11-01 13:58:06
【问题描述】:
我有一个关联数组,我在其中放置 DomElements。我只想从表中恢复一个单元格,所以我循环行($materie)并尝试为每个 9 列单元格提取。问题是 $cell[$o][9]->nodeValue (我放在 $DTO['materie'][$o]['prenotato'] 上)的结果对于每一轮都是相同的循环:它取第一个元素的值并保持不变。
for($o = 0; $o < sizeof($materie); $o++) {
$DTO['materie'][$o] = $materie[$o+1];
/**ROWS */
$cell = array();
$cell[$o] = $parserCommons->findElementsByTag($table[0], 'td');
$DTO['materie'][$o]['prenotato'] = $cell[$o][9]->nodeValue;
}
return $DTO;
这是函数体:
public function findElementsByTag($DOMArray, $tagName)
{
$output = $DOMArray->getElementsByTagname($tagName);
return $output;
}
【问题讨论】:
-
你能添加一个
$materie的内容和预期输出的例子吗? -
关联数组的元素具有字段 $DTO['materie'][$o]['prenotato'] 总是等于第一个元素的值,因此返回 1 - 1 -1 -1 -1。我希望它返回 1-2-3-4-5-6
标签: php associative-array