text: Program to print Step Pattern | function to print the steps ; declare a flag ; traverse through all the characters in the string ; if the x value is 0. . then we must increment till n ... set flag to true ; if the x value is n - 1 then we must decrement till 0 ... set flag as false ; print x * s ; checking whether to increment or decrement x ; Get the String and the number n ; calling the function
code: < ? php function steps ( $ str , $ n ) { $ x = 0 ; for ( $ i = 0 ; $ i < strlen ( $ str ) ; $ i ++ ) { if ( $ x == 0 ) $ flag = true ; if ( $ x == $ n - 1 ) $ flag = false ; for ( $ j = 0 ; $ j < $ x ; $ j ++ ) echo " * " ; echo $ str [ $ i ] , " STRNEWLINE " ; if ( $ flag == true ) $ x ++ ; else $ x -- ; } } $ n = 4 ; $ str = " GeeksForGeeks " ; echo " String : " , ▁ $ str , ▁ " " ; STRNEWLINE echo ▁ " Max Length of Steps : " , ▁ $ n , ▁ " " steps ( $ str , $ n ) ; ? >