If I add 1 hour and 35 minutes in PHP and subtract 4 hours, I get a remaining time of -3 hours and 30 minutes. But correct would be -2 hours and 30 minutes. Where’s the mistake? Answer $minutes – floor($minutes/60) is positive. So what you’re getting is -3 hours plus 30 minutes, which is -2:30. You need to treat
Tag: subtraction
Iterate array of arrays in reverse and subtract following subarray values from current subarray values
I have a dynamic multidimensional array like this: I need to loop through the subarrays and overwrite the current values of each subarray to represent the difference between the original value and the following value with respect to the subarray keys. This describes the arithmetic desired on each subarray element (the value after the = is the new desired value):