Jump to content

Using two entities for a key


Recommended Posts

I am currently using a single entity called id for a key.

I'm now wanting to use two entities as a key - id and size.

 

I've tried using these two peices of code, but failed:

foreach ($_SESSION['cart']['content'] as $key=>$product,$size) {
if ($product['id'] == $id && $product['size'] == $size) {
	$item_found = $key;
	break;
}
}
// do thing

... and

foreach ($_SESSION['cart']['content'] as $key=>$product && $key=>$size) {
if ($product['id'] == $id && $product['size'] == $size) {
	$item_found = $key;
	break;
}
}
// do thing

 

Am I going the right way about it? Can two entities even be used as a key?

Link to comment
Share on other sites

I don't think you're using the function correct.

I checked the php manual:http://php.net/manual/en/control-structures.foreach.php, however, I can't find an example like your implementation.

 

Maybe it could help if you would post what you are trying to achieve here, and what your array variable contains.

Link to comment
Share on other sites

I know you've been fighting this in a number of posts.  Why not use the product id as the key?  Even add the size if this is needed and the value would then be the quantity, i.e.  Array("143s" => 3, "122m" =>2).  Updating the quantity should be simple as you would know the key represents the product.  Just my two cents worth.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.