php - 没有 foreach 显示
问题描述
<?php
$pros_array_id= array_column($_SESSION['cart'], 'paint_id');
$productee = $productn->getData('paint');
foreach($productee as $pro):
if($pro['paint_id'] == $pros_array_id):
?>
<table>
<tr>
<td class="imgTag">
<a href="#"><img class="img-fluid" src="<?php echo $pro['paint_image'] ?? 1; ?>" ></a>
</td>
</tr>
</table>
<?php
endif;
endforeach;
?>
Am trying to display session cart items and its not showing anything. When I print_r($productee) and print_r($pros_array_id) after the foreach statement both display the accurate data, yet nothing displat in the <tr> tag.
当我像这样“$imp = implode(” “,$pros_array_id);” 内爆 $pros_array_id 时显示结果 并将变量放在 if 语句中,如果会话中只有一种产品,它可以正常工作,但是当我在会话中添加多个产品时,什么都不会再次显示。请有人指出我应该怎么做?谢谢
解决方案
试试这样:
<table>
<?php
$pros_array_id = array_column($_SESSION['cart'], 'paint_id');
$productee = $productn->getData('paint');
foreach($productee as $pro) {
//Also see and try to disable this check to see if it works then!
if($pro['paint_id'] == $pros_array_id) { ?>
<tr>
<td class="imgTag">
<a href="#"><img class="img-fluid" src="<?php echo $pro['paint_image'] ?? 1; ?>"></a>
</td>
</tr>
<?php
}
}
?>
</table>
始终确保在调试此类代码时消除任何可能导致错误的检查,因此请尝试禁用“if 子句”,以查看它是否显示了某些内容。
推荐阅读
- c - 最小化代码并获得相同的输出
- tfs - 使用凭据在共享网络路径上发布 TFS
- c - C中的便携式常数时间整数log2
- prometheus - Prometheus Cloudwatch Exporter 没有为 AWS ELB 返回正确的矩阵
- android - 如何检查 android 设备是否运行 10.2 或更高版本的 google play 服务
- svg - 如何使 svg 大小适合其内容?
- firebase - FCM 通知在 OREO 中不起作用
- vb.net - 如何禁用/抑制特定行的 Resharper 代码分析(Roslyn)?
- delphi-xe2 - 如何使用 idHTTP 连接设备
- javascript - 我无法重新启动我的音频文件