using previous number sum , finding the current number num of odd digit also , adding last digit if it is odd .
$ digitSum [ $ i ] = $ digitSum [ intval ( $ i / 10 ) ] + intval ( $ i & 1 ) * ( $ i % 10 ) ; } }