The variable I am trying to remove the values from is called $order

for example - $order is 485,894,1048,1040

I am trying to remove certain numbers which will vary each time these values are stored as $drinks_order

for example - $drinks_order is 1048,1040

So basically in the above example I wish to remove 1048 and 1040 from $order so I am then left with a new variable of $food_order which should be $food_order=485,894;

I have been trying this code but it doesn't seem to work properly

$nums = explode(',', $order);
$nums = array_diff($nums, array($drinks_order));
$food_order = implode(',', $nums);

Returns $food_order as 485,894,1048,1040

However when I test putting the actual numbers of $drinks_order in the code it removes them in the $food_order variable correctly

$nums = explode(',', $order);
$nums = array_diff($nums, array(1048,1040));
$food_order = implode(',', $nums);

Returns $food_order as 485,894

有帮助吗?

解决方案

$drinks_order = '1048,1040'; //must be a string
$nums = explode(',', $order);
$nums = array_diff($nums, explode(',', $drinks_order));
$food_order = implode(',', $nums);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top