Jump to content

Multi-dimensional array question


Harley1979

Recommended Posts

Hello,

 

Programing really isn't my strongest point so I'm after a little help here with something.

 

I am writting a simple shopping cart, what I specifically need to know is this.

 

If I write two id's into a multi-dimensional array;

 

$_SESSION['productItem'] = $productItem;
$_SESSION['productSize'] = $productSize;

$productItem .= ','.$_REQUEST['itemID'];
$productSize .= ','.$_REQUEST['sizeID'];

$myArray = ($productItem, $productSize);

 

How can I extract and seperate $productItem and $productSize again?

 

The sizes are pulled from a seperate table in the database so it is important that I'm able to extract the $productSize array for this functionality.

 

How would I best approach this?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/111651-multi-dimensional-array-question/
Share on other sites

If I understand you correctly.

 

Change your line to:

 

$myArray = array($productItem, $productSize);

 

Then read with $myArray[0] or $myArray[1].

 

For example:

 

<?php

$_SESSION['productItem'] = $productItem;
$_SESSION['productSize'] = $productSize;

$productItem .= ','.$_REQUEST['itemID'];
$productSize .= ','.$_REQUEST['sizeID'];

$myArray = array($productItem, $productSize);

//To test
echo "Item ".$myArray[0]." and size ".$myArray[1];

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.