Reverse a number using stack | Stack to maintain order of digits ; Function to push digits into stack ; Function to reverse the number ; Function call to push number 's   digits to stack ; Popping the digits and forming the reversed number ; Return the reversed number formed ; Driver Code ; Function call to reverse number
< ? php $ st = array ( ) ; function push_digits ( $ number ) { global $ st ; while ( $ number != 0 ) { array_push ( $ st , $ number % 10 ) ; $ number = ( int ) ( $ number / 10 ) ; } } function reverse_number ( $ number ) { global $ st ; push_digits ( $ number ) ; $ reverse = 0 ; $ i = 1 ; while ( ! empty ( $ st ) ) { $ reverse = $ reverse + ( $ st [ count ( $ st ) - 1 ] * $ i ) ; array_pop ( $ st ) ; $ i = $ i * 10 ; } return $ reverse ; } $ number = 39997 ; echo reverse_number ( $ number ) ; ? >