If non of the conditions are true , we iterate from A + 1 to B and multiply them . We are only concerned for the last digit , thus we take modulus of 10
for ( $ i = $ A + 1 ; $ i <= $ B ; $ i ++ ) $ variable = ( $ variable * ( $ i % 10 ) ) % 10 ; return $ variable % 10 ; } }