Home > Backend Development > PHP Tutorial > How to use php str_repeat function?

How to use php str_repeat function?

青灯夜游
Release: 2023-04-06 18:50:02
Original
3199 people have browsed it

php The str_repeat() function is used to create a new string by repeating a given string a fixed number of times and return the new string; the syntax is "str_repeat(string,repeat)", and the parameter string specifies to repeat The string parameter repeat specifies the number of times the string is repeated, which must be greater than or equal to 0.

How to use php str_repeat function?

php The str_repeat() function is used to create a new string by repeating a given string a fixed number of times. The syntax is str_repeat(string,repeat). It accepts a string and a

php How to use str_repeat function?

php The str_repeat() function can reuse the specified string. It is used to create a new string by repeating the given string a fixed number of times. The string is repeated by repeating the string passed as a parameter. Generated by the number of times defined by the integer passed as an argument to this function.

Syntax:

str_repeat(string,repeat)
Copy after login

Parameters:

● String: Required parameter, string to be repeated

● repeat: required parameter, specifies the number of times the string is repeated, which must be greater than or equal to 0.

Return value: str_repeat returns a new string consisting of repeating the given string $string a given number of times. If the parameter $no_of_times passed to the function is equal to 0, the function returns an empty string.

Example

<?php
$i = "hello world!";
$j = str_repeat($i,3);//设置字符串重复的次数为3
echo $j;
?>
Copy after login

Output:

hello world!hello world!hello world!
Copy after login

The above is the detailed content of How to use php str_repeat function?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template