Home  >  Article  >  Backend Development  >  How to repeat a string several times in php

How to repeat a string several times in php

青灯夜游
青灯夜游Original
2022-02-11 17:22:063652browse

In PHP, you can use the str_repeat() function to repeat a string a specified number of times and return the repeated string; the syntax "str_repeat(string,repeat)", the parameter "repeat" specifies the string The number of times it will be repeated, its value must be greater than or equal to 0.

How to repeat a string several times in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In PHP, you can use the str_repeat() function to repeat a string a specified number of times.

str_repeat() function repeats a string a specified number of times.

Syntax:

str_repeat(string,repeat)

The parameter string specifies the string to be repeated, and the parameter repeat specifies the number of times the string will be repeated. The str_repeat() function returns the result of string repeated repeat times.

Note: The value of parameter repeat must be greater than or equal to 0; if repeat is set to 0, the function will return an empty string.

Example:

";
echo "重要的事情说三遍:
" . str_repeat($str, 3); ?>

How to repeat a string several times in php

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to repeat a string several times in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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