Check if a number is a power of another number | Returns 1 if y is a power of x ; The only power of 1 is 1 itself ; Repeatedly comput power of x ; Check if power of x becomes y ; check the result for true / false and print .
< ? php function isPower ( $ x , $ y ) { if ( $ x == 1 ) return ( $ y == 1 ? 1 : 0 ) ; $ pow = 1 ; while ( $ pow < $ y ) $ pow *= $ x ; return ( $ pow == $ y ? 1 : 0 ) ; } echo isPower ( 10 , 1 ) . " STRNEWLINE " ; echo isPower ( 1 , 20 ) . " STRNEWLINE " ; echo isPower ( 2 , 128 ) . " STRNEWLINE " ; echo isPower ( 2 , 30 ) . " STRNEWLINE " ; ? >