php - 在 codeigniter 中查看数组到字符串的转换
问题描述
我不明白为什么我的变量 $product_quantity 出现错误,而它的 $var_dump($product_quantity) 给出了元素。代码片段中指示的错误点为第 63 行。此外,它没有得到 $productInfo['image'] 和 $productInfo['url']。在此处检查 $var_dump($product_quantity) 的输出
<?php
$arr_products = unserialize($order['products']);
foreach($arr_products as $product_id => $product_quantity)
{
$productInfo = modules::run('admin/ecommerce/products/getProductInfo', $product_id, true);
var_dump($product_quantity);
?>
<div style="word-break: break-all;">
<div>
<img src="<?= base_url('attachments/shop_images/'.$productInfo['image']) ?>" alt="Product" style="width:100px; margin-right:10px;" class="img-responsive">
</div>
<a target="_blank" href="<?= base_url($productInfo['url']) ?>">
<?= base_url($productInfo['url']) ?>
</a>
<--line 63-->
<div style=" background-color: #f1f1f1; border-radius: 2px; padding: 2px 5px;"><b><?= lang('user_order_quantity') ?></b> <?= $product_quantity ?></div>
</div>
<hr>
<?php }
?>
解决方案
如您var_dump
的数组所示,它是一个多级关联数组,其父键为product_info
and product_quantity
。
我怀疑如果您将有问题的行更改为<?php echo $product_quantity['product_quantity']; ?>
您将不再有错误。
此外,您似乎也$product_quantity
包含您的内容product_info
,所以我不确定这是否完全有必要$productInfo = modules::run('admin/ecommerce/products/getProductInfo', $product_id, true);
(不知道您的整个系统,所以我可能错了)
推荐阅读
- java - Tomcat 9 通用类加载器是 URLClassLoader 吗?
- javascript - 如何在 javascript/jquery 中显示相对于视口而不是网页的弹出元素?
- pandas - 熊猫转轴?数据透视表?熔化?堆叠还是取消堆叠?
- css - Chrome 正在剪裁 SVG 图像的边缘,而其他浏览器则没有
- javascript - Javascript 检测在同一个浏览器中打开的两个表单
- opencv - 如果您在图像中有一个对象的方向,您如何找到它的平移?
- python-3.x - 在 python 中使用 MongoDb 查找查询
- snowflake-cloud-data-platform - Snowflake S3 集成文件命名的预期行为?
- c# - 通过 HttpClient 抛出错误的真正快速的 PostAsync 调用
- node.js - 部署 VueJS 应用程序 - 后端 (ExpressJS) 没有响应