PHP str_repeat() Function
In this chapter you will learn:
- Definition for PHP str_repeat() Function
- Syntax for PHP str_repeat() Function
- Parameter for PHP str_repeat() Function
- Return for PHP str_repeat() Function
- Example - Repeat the string 3 times
Definition
The str_repeat() function repeats a string a specified number of times.
Syntax
PHP str_repeat() Function has the following syntax.
str_repeat(string,repeat)
Parameter
Parameter | Is Required | Description |
---|---|---|
string | Required. | String to repeat |
repeat | Required. | Number of times to repeat. Must be greater or equal to 0 |
Return
PHP str_repeat() function returns the repeated string.
Example
Repeat the string "java2s.com" 3 times:
<?php
echo str_repeat("java2s.com",3);
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP str_replace() Function
- Syntax for PHP str_replace() Function
- Parameter for PHP str_replace() Function
- Return for PHP str_replace() Function
- Example - how to use str_replace()
Home » PHP Tutorial » PHP String Functions