I'm working on a Laravel project and came cross this function which took me to much time trying to understand how it works but with no luck! can people with more experience explain how it works.
$seller_products = array();
foreach ($carts as $cartItem) {
$product_ids = array();
$product = Product::find($cartItem['product_id']);
if (isset($seller_products[$product->user_id])) {
$product_ids = $seller_products[$product->user_id];
}
array_push($product_ids, $cartItem);
$seller_products[$product->user_id] = $product_ids;
}