首页 > 解决方案 > 如何删除prev foreach数据

问题描述

foreach ($products as $product) {
    echo "SIZE (X х Y х Z),mm: ";
    $myf = [8,4,5]; // my custom fields is X,Y,Z and print it           
    foreach($product->customfields as $field){ // get fields
        if (in_array($field->virtuemart_custom_id, $myf)) {
            $output[] = $field->customfield_value;
        }
    }
    echo implode('x', $output); // is getting re-assigned each time. So whatever the problem is, it is a result of whatever $output is getting assigned with.
}

在第二个产品中,我有来自第一个产品的数据

尺寸(X х Y х Z),mm:280x260x350x290x325x435(仅需要 290x325x435!)。 在每个产品上,我都有所有以前产品的所有以前的 XYZ 数据。

非常错误。请帮助仅将数据 1 XYZ 打印到 1 个产品:)

我认为内爆不正确的方法

标签: phparraysregexarraylistjoomla

解决方案


就在这条线之后

echo implode('x', $output);

添加这一行

unset($output);

这样做的目的是将您重置$output为一个空数组。您的 $output 不再具有以前的数据。


推荐阅读