<?php
$cart_items = '[
{"id":8,
"cart_id":7,
"product_id":4,
"variation_id":null,
"quantity":1,
"price":30,
"tax":0,
"attrs":null,
"gross_total":30,
"net_total":30,
"tax_total":0,
"product":{
"id":4,
"parent_id":null,
"category_id":1,
"shop_id":1,
"title":"Ladies Blazer",
"unit":"item",
"sale_price":30,
"general_price":35
}
},
{
"id":9,
"cart_id":7,
"product_id":1,
"variation_id":null,
"quantity":2,
"price":11,
"tax":0,
"attrs":null,
"gross_total":22,
"net_total":22,
"tax_total":0,
"product":{
"id":1,
"parent_id":null,
"category_id":2,
"shop_id":2,
"title":"Sport Bottles",
"unit":"item",
"sale_price":11,
"general_price":9
}
}
]';
$arr = json_decode($cart_items, true);
$shop_id = 1;
$result = array_filter($arr, fn($v) => $v["product"]["shop_id"] == $shop_id);
var_export($result);
preferences:
18.15 ms | 402 KiB | 5 Q