我使用的是像这样的简单HTML DOM:
foreach($html->find('img', 18) as $d) {
echo $d->outertext;
}
现在我想实现一个变量数组,在本例中是图像,所以我做到了:
$img=array(
"img"=>"18",
"img"=>"21"
);
foreach($img as $x=>$x_value)
{
$d = $html->find($x, $x_value);
echo $d->outertext;
}
问题是SimpleHTMLDOM只返回数组中的最后一个图像,即数字21。我该怎么做才能让它返回数组中的所有内容?
这是因为$img
数组中的两个项具有相同的键。CCD_ 2不将它们识别为两个独立的项,因为两个键都是CCD_。
要演示的示例代码:
$test = array(
"key" => 1,
"key" => 2
);
echo "Length of array: " . count($test) . "'n'n";
echo "Items in array:'n";
foreach($test as $key => $value) {
echo "$key => $value'n";
}
输出:
Length of array: 1
Items in array:
key => 2