Not sure if we understand your question correctly, but the $r->result has an array route with the sorted locations by the algorithm. Each location has its estimated arrival in minutes and distance in km. If you get these from the last item in the array, that’s the total duration and distance for the route.
I will try to express myself better.
When I try to retrieve just the first arrival and distance of the first location after departure from result I get this error.
Warning : Undefined variable $result in ******* on line 149
Warning : Trying to access array offset on value of type null in ******* on line 149
Fatal error : Uncaught TypeError: array_values(): Argument #1 ($array) must be of type array, null given in ***:149 Stack trace: #0 ***(149): array_values(NULL) #1 {main} thrown in ******** on line 149