如何从PHP中的会话中提取数据? [英] How to pull out data from session in PHP?

查看:55
本文介绍了如何从PHP中的会话中提取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有来自 print_r($_SESSION) 的以下数据:

I have the following data from print_r($_SESSION):

Array (
[totalprice] => 954
[cart] => Array (
      [115] => Array (
          [name] => MÅNESKINN
          [price] => 268.00
          [count] => 1 )
      [80] => Array (
          [name] => DELFINLEK  
          [price] => 268.00
          [count] => 1 )
      [68] => Array (
          [name] => OPPDAGELSEN
          [price] => 418.00
          [count] => 1 )
      )
[shipping] => 65 ) 

现在我想从这个会话中取出所有的价格 268.00 和 418.00.

Now I want to pull out all the price 268.00 and 418.00 from this session.

我该怎么做?

我尝试了 $_SESSION['cart']['price'],但它不起作用.

I tried $_SESSION['cart']['price'], but it does not work.

推荐答案

$_SESSION['cart'] 是一个数组.如果您只需要一行 - 那就是

$_SESSION['cart'] is an array. If you need only one row - it would be

$_SESSION['cart'][115]['price']

但你最好遍历数组:

foreach($_SESSION['cart'] as $item){
    echo $item['price'];
}

这篇关于如何从PHP中的会话中提取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆