text: Count set bits in an integer | recursive function to count set bits ; base case ; get value from user ; function calling
code: < ? php function countSetBits ( $ n ) { if ( $ n == 0 ) return 0 ; else return 1 + countSetBits ( $ n & ( $ n - 1 ) ) ; } $ n = 9 ; echo countSetBits ( $ n ) ; ? >