Hi,

This is my array and i want to make [2] => 1 to [2] => 4
How do i do it?

Thanks

Array
(
    [SESSION] => hs6f5ul7q9dic13nv7crikf0p2
    [USER] => Guest
    [5] => 3
    [1] => 3
    [2] => 1
    [7] => 1
)

This code doesn't do it.

foreach($cookieInfo as $key=>$value) {
		if ($key == "SESSION") {
			$cookieValue["SESSION"]=$sessionID;
		} else if ($key == "USER") {
			$cookieValue["USER"]=$user;
		} else if ($key != $productID) {
			$cookieValue[$key] = $value;
		} else if ($key == $productID) {		
			$newAmount = $value+$productAmount;
			$cookieValue[$key] = $newAmount;
		}
	}

Ok. Solved,

I use "array_key_exists" function to find the key to remove it first and add it again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.