<?php
class warehouse
{
public function __construct(private int $id, private int $capacity, private array $items)
{
}
public function getId()
{
return $this->id;
}
}
class inventory_feed
{
public function __construct(private int $id, private int $warehouseId, private string $code)
{
}
public function getWarehouseId()
{
return $this->warehouseId;
}
}
$warehouse_1 = new warehouse(1, 100, [1,2,3,4]);
$warehouse_2 = new warehouse(2, 1100, [1,2,3,4]);
$warehouse_3 = new warehouse(3, 12000, [1,2,3,4]);
$warehouse_4 = new warehouse(4, 130000, [1,2,3,4]);
$warehouse_5 = new warehouse(5, 1400000, [1,2,3,4]);
$inventory_feed_1 = new inventory_feed(12, 1, "2as21332kjd");
$inventory_feed_2 = new inventory_feed(10, 2, "2123asagfrtsdd");
$inventory_feed_3 = new inventory_feed(11, 3, "2as1231sds2d");
$inventory_feed_4 = new inventory_feed(13, 4, "2as1231sds2d");
$inventory_feed_5 = new inventory_feed(14, 5, "2as1231sds2d");
$ifeeds = [
"a" => $inventory_feed_1,
"b" => $inventory_feed_2,
"c" => $inventory_feed_3
];
$warehouses = [
$warehouse_1,
$warehouse_2,
$warehouse_3,
$warehouse_4,
$warehouse_5
];
$feedMap = array_fill_keys(array_map(fn($obj) => $obj->getWarehouseId(), $ifeeds), true);
$warehouses_filtered = array_filter($warehouses, fn($warehouse) => isset($feedMap[$warehouse->getId()]));
var_export($warehouses_filtered);
- Output for 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
- array (
0 =>
\warehouse::__set_state(array(
'id' => 1,
'capacity' => 100,
'items' =>
array (
0 => 1,
1 => 2,
2 => 3,
3 => 4,
),
)),
1 =>
\warehouse::__set_state(array(
'id' => 2,
'capacity' => 1100,
'items' =>
array (
0 => 1,
1 => 2,
2 => 3,
3 => 4,
),
)),
2 =>
\warehouse::__set_state(array(
'id' => 3,
'capacity' => 12000,
'items' =>
array (
0 => 1,
1 => 2,
2 => 3,
3 => 4,
),
)),
)
- Output for 8.1.0 - 8.1.28
- array (
0 =>
warehouse::__set_state(array(
'id' => 1,
'capacity' => 100,
'items' =>
array (
0 => 1,
1 => 2,
2 => 3,
3 => 4,
),
)),
1 =>
warehouse::__set_state(array(
'id' => 2,
'capacity' => 1100,
'items' =>
array (
0 => 1,
1 => 2,
2 => 3,
3 => 4,
),
)),
2 =>
warehouse::__set_state(array(
'id' => 3,
'capacity' => 12000,
'items' =>
array (
0 => 1,
1 => 2,
2 => 3,
3 => 4,
),
)),
)
preferences:
77.29 ms | 402 KiB | 62 Q