Count changes in Led Lights to display digits one by one | PHP program to count number of on offs to display digits of a number . ; store the led lights required to display a particular number . ; compute the change in led and keep on adding the change ; Driver code
< ? php function countOnOff ( $ n ) { $ Led = array ( 6 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 5 ) ; $ len = strlen ( $ n ) ; $ sum = $ Led [ $ n [ 0 ] - '0' ] ; for ( $ i = 1 ; $ i < $ len ; $ i ++ ) { $ sum = $ sum + abs ( $ Led [ $ n [ $ i ] - '0' ] - $ Led [ $ n [ $ i - 1 ] - '0' ] ) ; } return $ sum ; } $ n = "082" ; echo countOnOff ( $ n ) ; ? >