php - array_key_exists() expects parameter 2 to be array, null given - Cakephp 3

one text

Solution:

When you do this:

$cart[] = $order;

you are asking PHP to add a new element to the end of your $cart array, giving it the next available numeric key. You are then trying to see if the product id exists as a key in the array. Unless your product ids are like 0 and 1, that's unlikely to ever happen. If you want your cart to be keyed by product id, use

$cart[$order->product_id] = $order;

Source