Multidimensional Arrays

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chuck2282
Forum Newbie
Posts: 1
Joined: Sun Aug 21, 2011 2:51 pm

Multidimensional Arrays

Post by chuck2282 »

Hi,

I have an array that I'm having trouble with. Below is how Im accessing it and the dump output

Code: Select all

$cart = $_SESSION['cart']->contents;
var_dump($cart);

array(2) { [11880]=> array(1) { ["qty"]=> string(1) "1" } [9132]=> array(1) { ["qty"]=> float(2) } } 
I'm trying to assing 11880 to a product_id and the value of qty to variables. And the same with 9132... How can I loop through this array and store these values?

I don't have much experence with Multidimensional Arrays and any help is much appreciated.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Multidimensional Arrays

Post by AbraCadaver »

Code: Select all

foreach($cart as $key => $value) {
   echo $key . ' ' . $value['qty'];
}
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply