开发者

printing from multidimensional arrays?

开发者 https://www.devze.com 2022-12-29 18:26 出处:网络
I have a multi array that looks like this: $_SESSION[\'cartItems\'][\'quantity\'] How do I print out its val开发者_运维技巧ues? print_r won\'t work, unless $_SESSION doesn\'t support multi-dimensio

I have a multi array that looks like this:

$_SESSION['cartItems']['quantity']

How do I print out its val开发者_运维技巧ues? print_r won't work, unless $_SESSION doesn't support multi-dimensional arrays?


print_r($_SESSION['cartItems']); should work.


you can use var_dump($_SESSION). However, print_r should work. Make sure you are doing print_r($_SESSION), and not trying to print_r your variable that may not exist.


If you want to get the quantity of each card item in the array, you can do this:

$quantities = array_map(create_function('item', "$item['quanitity']"), $_SESSION['cardItems']);

// PHP 5.3
$quantities = array_map(function($item) {
    return $item['quanitity'];
}, $_SESSION['cardItems']);
0

精彩评论

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