fork download
  1. <?php
  2.  
  3. class warehouse {
  4. function __construct($id, $x, $y) {
  5. $this->id = $id;
  6. }
  7. function getId() {
  8. return $this->id;
  9. }
  10. }
  11.  
  12. class inventory_feed {
  13. function __construct($id, $warehouse, $x) {
  14. $this->id = $id;
  15. $this->warehouse_id = $warehouse;
  16. }
  17. function getWarehouseId() {
  18. return $this->warehouse_id;
  19. }
  20. }
  21.  
  22. $warehouse_1 = new warehouse(1, 100, [1,2,3,4]);
  23. $warehouse_2 = new warehouse(2, 1100, [1,2,3,4]);
  24. $warehouse_3 = new warehouse(3, 12000, [1,2,3,4]);
  25. $warehouse_4 = new warehouse(4, 130000, [1,2,3,4]);
  26. $warehouse_5 = new warehouse(5, 1400000, [1,2,3,4]);
  27.  
  28. $inventory_feed_1 = new inventory_feed(12, 1, "2as21332kjd");
  29. $inventory_feed_2 = new inventory_feed(10, 2, "2123asagfrtsdd");
  30. $inventory_feed_3 = new inventory_feed(11, 3, "2as1231sds2d");
  31. $inventory_feed_4 = new inventory_feed(13, 4, "2as1231sds2d");
  32. $inventory_feed_5 = new inventory_feed(14, 5, "2as1231sds2d");
  33.  
  34. $ifeeds = ["a" => $inventory_feed_1, "b" => $inventory_feed_2, "c" => $inventory_feed_3];
  35. $warehouses = [$warehouse_1, $warehouse_2, $warehouse_3, $warehouse_4, $warehouse_5];
  36.  
  37. $warehouses_filtered = array_filter(
  38. $warehouses,
  39. function ($warehouse) use ($ifeeds) {
  40. foreach($ifeeds as $ifeed_id => $ifeed) {
  41. if ($ifeed->getWarehouseId() == $warehouse->getId()) {
  42. return true;
  43. }
  44. }
  45. return false;
  46. });
  47.  
  48. var_dump($warehouses_filtered);
  49.  
Success #stdin #stdout 0.02s 25948KB
stdin
Standard input is empty
stdout
array(3) {
  [0]=>
  object(warehouse)#1 (1) {
    ["id"]=>
    int(1)
  }
  [1]=>
  object(warehouse)#2 (1) {
    ["id"]=>
    int(2)
  }
  [2]=>
  object(warehouse)#3 (1) {
    ["id"]=>
    int(3)
  }
}