Arrays 在嵌套数组中引用变量
我试图在这个嵌套数组中引用建议的变量,因为它从for循环中吐出$_会话[产品]->建议的,不起作用。还有其他类似的问题,但答案很难理解。下面是for循环Arrays 在嵌套数组中引用变量,arrays,variables,nested,Arrays,Variables,Nested,我试图在这个嵌套数组中引用建议的变量,因为它从for循环中吐出$_会话[产品]->建议的,不起作用。还有其他类似的问题,但答案很难理解。下面是for循环 array(1) { ["products"]=> array(1) { [0]=> array(9) { ["name"]=> string(20) "m10x1-5-001 IVB bolt" ["code"]=> string(11) "m10x1-5-0
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 ....."
}
}
}
我尝试使用的循环:如果语句被破坏,cart会话中的每个项目都会附加一个建议的项目,因为循环可以正常工作
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>';
}
可以像访问对象的属性一样链接嵌套数组的键或索引
$_SESSION["products"]["suggested"]
我应该帮你解决你的问题