为什么我的数组正在重新设置密钥编号


Why is my array reseting the key number?

我使用的是这个html解析器,它搜索html元素,并在它们出现时将其打印在屏幕上

有些是ID有些是H4

现在的问题是,在它找到一个ID后,它会寻找H4

现在,当我在最后为每个循环做一个时,只有H4出现,但没有一个价格的

我想知道为什么会这样

我是一个新手,喜欢PHP,但我不明白为什么密钥是重置和伪造ID密钥

代码=>

<?php 
ini_set('memory_limit','128M');
set_time_limit(0);
include_once('simple_html_dom.php');
$target_url= "ethicon2.html";
$html = new simple_html_dom();
$html -> load_file($target_url);
$line = 0;                 
$ref = $html-> find('.price');                  
$ref = $html-> find('h4');              
$ref = $html-> find('h4');
foreach ($ref as $value) {
    print "$value<br>";
}
?>

尝试将它们添加到数组中,如下所示:

$ref[] = $html-> find('.price');                  
$ref[] = $html-> find('h4');              
$ref[] = $html-> find('h4');

编辑如果你想让这些出现在一个数组中,试试这个

$ref2 = array();
foreach($ref as $r)
{
    $ref2 = array_merge($ref2,$r);
}
print_r($ref2);