开发者

How to pull out data from session in PHP?

开发者 https://www.devze.com 2022-12-16 11:22 出处:网络
I have the following data from print_r($_SESSION): Array ( [totalprice] => 954 [cart] => Array ( [115] => Array (

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 ) 

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

How can 开发者_开发百科I do it?

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


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

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

But you'd better walk through array:

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

精彩评论

暂无评论...
验证码 换一张
取 消