i have a problem about looping sequential

i have targeted to solve this problem but i am stuck till now using php
this case iterates sequentially to get time or date range (dataset)

data collection
$array = array(‘2021-06-12’, ‘2021-07-14’, ‘2022-08-05’, ‘2022-09-20’);
$single_array = array();

what I want like this is different
first iteration = date difference 2021-06-12 2021-07-14 = result (push to single_array)
next loop = 2022-08-05 date difference 2022-09-20 = result (push to single_array again)

and the next process will show the results when the array has been collected into a single array before to get the most average.