Smarandache | Function to collect first ' n ' prime numbers ; List to store first ' n ' primes ; Function to generate Smarandache - Wellin Sequence ; Storing the first ' n ' prime numbers in a list ; Driver Code
< ? php function primes ( $ n ) { $ i = 2 ; $ j = 0 ; $ result ; $ z = 0 ; while ( $ j < $ n ) { $ flag = true ; for ( $ item = 2 ; $ item <= ( int ) ( $ i * 1 / 2 ) ; $ item ++ ) if ( $ i % $ item == 0 && $ i != $ item ) { $ flag = false ; break ; } if ( $ flag ) { $ result [ $ z ++ ] = $ i ; $ j += 1 ; } $ i += 1 ; } return $ result ; } function smar_wln ( $ n ) { $ arr = primes ( $ n ) ; for ( $ i = 0 ; $ i < count ( $ arr ) ; $ i ++ ) { for ( $ j = 0 ; $ j <= $ i ; $ j ++ ) echo $ arr [ $ j ] ; echo " ▁ " ; } } $ n = 5 ; echo " First ▁ $ n ▁ terms ▁ of ▁ the " . " ▁ Sequence ▁ are STRNEWLINE " ; smar_wln ( $ n ) ; ? >