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']);
精彩评论