微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

没有 foreach 显示

如何解决没有 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.

显示结果 当我像这样内爆 $pros_array_id 时 "$imp = implode(" ",$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 子句”,以查看它是否显示某些内容。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。