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
https://forums.phpfreaks.com/topic/248683-using-two-entities-for-a-key/
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.

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.

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.