php - 如何删除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 个产品:)
我认为内爆不正确的方法
解决方案
就在这条线之后
echo implode('x', $output);
添加这一行
unset($output);
这样做的目的是将您重置$output
为一个空数组。您的 $output 不再具有以前的数据。
推荐阅读
- python - 有没有办法从视图函数中访问 WTForms RadioField 标签?
- c++ - 如何从文件系统获取 std::string 或 char[]?
- shell - 为什么 awk 给我一个致命错误:I/O?
- postgresql - 使用“order by”、“limit”和“union”加速查询
- javascript - 反模式:在减速器中访问状态?如何处理相互依赖的减速器?
- linux - stat() 系统函数在 Linux 7.6 中不起作用
- python - python中缺乏一致性,函数前定义变量的行为完全矛盾
- google-cloud-firestore - firestore 规则 get() / exists() 不起作用
- delphi - Delphi 字幕进度条
- javascript - 执行数据库绑定后项目为空