How can PHP be used to efficiently handle the removal of customer assignments from objects?

When removing customer assignments from objects in PHP, one efficient way to handle this is by using a loop to iterate through the objects and check if the customer assignment needs to be removed. This can be done by comparing the customer ID to the one that needs to be removed and then unsetting the assignment if a match is found.

// Sample array of objects with customer assignments
$objects = [
    ['id' => 1, 'customer_id' => 100],
    ['id' => 2, 'customer_id' => 200],
    ['id' => 3, 'customer_id' => 100],
];

// Customer ID to be removed
$customerToRemove = 100;

// Loop through the objects and remove customer assignments
foreach ($objects as $key => $object) {
    if ($object['customer_id'] == $customerToRemove) {
        unset($objects[$key]['customer_id']);
    }
}

// Output updated objects array
print_r($objects);