I’m currently trying to use array_diff to remove 1 value from an array.
The code looks like this right now:
$item_id = 501;
$array = array_diff($user_items, array($item_id));
user items array: 501,501,502,502
results correctly in array: 502,502
Is it possible to remove only 1×501 instead of 2×501 value? or said differently: limit the removal by 1 value
array is then: 501,502,502
Any advice is appreciated
How about searching for the item, then removing it if it exists?
Using
unsetisn’t quite as straightforward as you’d think. See Stefan Gehrig’s answer in this similar question for details.