3v4l.org

run code in 300+ PHP versions simultaneously
<?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);
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
array ( 0 => array ( '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' => array ( 'id' => 4, 'parent_id' => NULL, 'category_id' => 1, 'shop_id' => 1, 'title' => 'Ladies Blazer', 'unit' => 'item', 'sale_price' => 30, 'general_price' => 35, ), ), )

preferences:
125.78 ms | 403 KiB | 121 Q