Find an array element such that all elements are divisible by it | function to find smallest num ; Find the smallest element ; Check if all array elements are divisible by smallest . ; Driver Code
< ? php function findSmallest ( $ a , $ n ) { $ smallest = min ( $ a ) ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) if ( $ a [ $ i ] % $ smallest ) return -1 ; return $ smallest ; } $ a = array ( 25 , 20 , 5 , 10 , 100 ) ; $ n = count ( $ a ) ; echo findSmallest ( $ a , $ n ) ; ? >