0
我试图引用此嵌套数组中的“建议”变量,因为它会吐出for循环。 $ _SESSION [“产品”] - >建议,没有工作。还有其他类似的问题,但答案很难遵循。 for循环如下。引用嵌套数组中的变量
array(1) {
["products"]=>
array(1) {
[0]=>
array(9) {
["name"]=>
string(20) "m10x1-5-001 IVB bolt"
["code"]=>
string(11) "m10x1-5-001"
["qty"]=>
string(1) "1"
["weight"]=>
string(3) ".03"
["price"]=>
string(5) "37.00"
["image"]=>
string(80) "/images/ProductPhotosLR/m101-5-001/m10x1-5-001-S.jpg"
["description"]=>
string(39) "This is a short description of my item."
["suggested"]=>
string(18) "IVB-METRIC-INSTALL"
["suggestedtext"]=>
string(80) "First time owners of ....."
}
}
}
环路我试图使用方法:(每个项目在购物车会议将有可能附着建议项目)的循环工作正常,如果语句被分解。
if(!empty($_SESSION["products"]->suggested)) {
echo '<div id="products-wrapper"><h1>Suggested Items</h1><div class="view-cart">';
echo '<table width="750" cellpadding="0" cellspacing="0" style="text-align:center;padding:5px;">';
foreach ($_SESSION["products"] as $cart_itm)
{
echo '<tr><td>'.$cart_itm['suggested'].' '.$cart_itm['suggestedtext'].'</td></tr>';
}
echo '</table></div></div>';
}