I have an array of values [20,40,30,50] and I have another variable with value 30.

I need to subtract 30 from the first element.
And if $var is greater then need to delete the first element and subtract remaining value from next element in the array.

Example: 
$arr = array(20,40,30,50);
$var = 30;

The result array should be (30,30,50)

Thank you