内爆一个阵列,然后移动到下一个阵列


Implode one array then move onto the next array

在foreach循环中内爆多个数组有一个小问题。

数组现在是这样的:

Array (
[0] => Array ( [img] => /Content/ProductImages/big/9414339613250.jpg [prodtitle] => Heineken Lager 330ml Btls [unit] => 12pk [price] => [wasprice] => 26.99 [specprice] =>      ) 
[1] => Array ( [img] => /Content/ProductImages/big/7501064191367.jpg [prodtitle] => Corona Extra Beer 355ml Bottles [unit] => 12pk [price] => [wasprice] => 26.99 [specprice] => 22.99 )     
[2] => Array ( [img] => /Content/ProductImages/big/9414774095307.jpg [prodtitle] => Steinlager Lager 330ml Btls [unit] => 12pk [price] => [wasprice] => 23.99 [specprice] => 21.99 )

然而,在foreach循环中,它只对第一个数组进行内爆循环的次数为:

/Content/ProductImages/big/9414339613250.jpg','Heineken Lager 330ml Btls ','12pk ','','26.99','20.99
/Content/ProductImages/big/9414339613250.jpg','Heineken Lager 330ml Btls ','12pk ','','26.99','20.99
/Content/ProductImages/big/9414339613250.jpg','Heineken Lager 330ml Btls ','12pk ','','26.99','20.99

我想让它遍历每个数组。数字或数组不是特定的,因为可以添加或减去项。

/Content/ProductImages/big/9414339613250.jpg','Heineken Lager 330ml Btls ','12pk','','26.99','20.99
/Content/ProductImages/big/7501064191367.jpg','Corona Extra Beer 355ml Bottles ','12pk ','','26.99','22.99

整个代码看起来像这样:

$html = file_get_html($url);
foreach($html->find('div.product-details-contents') as $content) {
    $detail['img'] = $content->find('img.product-details-image',0)->src;
    $detail['prodtitle'] = $content->find('span.title', 0)->plaintext;
    $detail['unit'] = $content->find('span.unit-size', 0)->plaintext;
    $detail['price'] = filter_var($content->find('span.price', 0)->plaintext, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION | FILTER_FLAG_ALLOW_THOUSAND);
    $detail['wasprice'] = filter_var($content->find('span.was-price', 0)->plaintext, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION | FILTER_FLAG_ALLOW_THOUSAND);
    $detail['specprice'] = filter_var($content->find('span.special-price', 0)->plaintext, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION | FILTER_FLAG_ALLOW_THOUSAND);
    $product[] = $detail;
    $sqlstring = implode("','", $product[0]);
    echo $sqlstring;
}
print_r($product);

$sqlstring = implode("','", $product[0]);$product[0]的数目增加时,它给出如下错误:

警告:内爆()[函数。

:传入无效参数。

您说只有第一个数组被内爆。嗯,看起来是这样的:

$sqlstring = implode("','", $product[0]);

这段代码总是内爆product数组的第一个元素。为什么不做SMTH:

$sqlstring = implode("','", $detail);