fork download
  1. <?php
  2.  
  3. $cart1 = new StdClass;
  4. $cart1->id = 123;
  5. $cart1->size_id = 2;
  6.  
  7. $cart2 = new StdClass;
  8. $cart2->id = 123;
  9. $cart2->size_id = 3;
  10.  
  11. $cart_array = array_filter(
  12. [$cart1, $cart2],
  13. function ($item) {
  14. return $item->id != 123 && $item->size_id != 2;
  15. }
  16. );
  17.  
  18. echo 'Test 1:' . PHP_EOL;
  19. print_r($cart_array);
  20.  
  21. $cart_array = array_filter(
  22. [$cart1, $cart2],
  23. function ($item) {
  24. return $item->id == 123 && $item->size_id != 2;
  25. }
  26. );
  27.  
  28. echo 'Test 2:' . PHP_EOL;
  29. print_r($cart_array);
Success #stdin #stdout 0.01s 82880KB
stdin
Standard input is empty
stdout
Test 1:
Array
(
)
Test 2:
Array
(
    [1] => stdClass Object
        (
            [id] => 123
            [size_id] => 3
        )

)