-2
我有一段代码需要使用echo函数来打印会话数组中的变量,另一方面,我需要每次都要逐个添加价格用户选择产品。价格变量是一个字符串。代码,如下所示:使用echo函数打印元素的多维会话数组
if (!is_array($_SESSION['products']['names'])){
$_SESSION['products']['names']['name'] = array();
$_SESSION['products']['names']['prices']= array();
}else {
$pros = $_SESSION['products']['names']['name'];
if (in_array($product->getName(), $pros, true)){
echo 'The product is available in your basket';
} else {
$prozuct = array_push($_SESSION['products']['names']['name'],$product->getName());
array_push($_SESSION['products']['names']['prices'], $product->getPrice(Currency::getCurrentCurrency()));
foreach ($_SESSION['products'] as $id=>$arr){
for ($i=0;$i<count($arr);$i++){
echo $arr['name'][$i];
}
}
}
}
我接收是错误:
注意:未定义偏移:1 /用户
并且另外我知道我可以使用的print_r但在我的情况下,我想逐个添加价格并计算并显示用户总额。
请告诉我与前三行怎么回事? – Steve
这是一个阿贾克斯请求调用 –
我很高兴你找到你的解决方案。只是一个简短的说明 - 我们倾向于劝阻'请求帮助'和'紧急'请求 - 幸运的是,你的问题并不比其他问题更重要。请不要将此添加到问题 - 谢谢! – halfer