SQL PHP HTML ASP JavaScript articles and free scripts to download
 

Repeating String str_repeat function

Using str_repeat string function we can repeat a string by a number ( known as multiplier ). Say we want to repeat a string $ for ten times, here is the syntax for the function str_repeat.

str_repeat (input string, int multiplier );



Here is one example

echo str_repeat(“$”,10);



The above command will print $ ten times.

Now let us move to another example. How about printing such a pattern ?

*
**
***
****
*****
******
*******
********
*********
**********

Here is the code for this

for($i=1;$i<=10;$i++){
echo str_repeat("*",$i);
echo "<br>";
}




Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked


Join Our Email List
Email:  
For Email Newsletters you can trust
String Functions
PHP Sections