How PHP copies strings and outputs
This article mainly introduces PHP how to copy the string and output, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
The specific question is "write a PHP program to create a new string that is n (non-negative integer) times a given string, such as the string ab- > becomes ababab (three times the original string)"?
Several key points:
1. There are two string (string) operators in PHP. The first is the concatenation operator ("."), which returns the concatenated string of its left and right arguments. The second is the concatenation assignment operator (. =), which appends the parameter on the right to the parameter on the left.
2. In PHP, the for loop is used to know in advance how many times a script needs to be run.
For (initial value; condition; Increment) {Code to be executed;} Parameter: initial value: mainly initializes a variable value, which is used to set a counter (but it can be any code that is executed once at the beginning of the loop). Condition: the constraint on the execution of the loop. If TRUE, the loop continues. If FALSE, the loop ends. Increment: mainly used for incrementing counters (but can be any code that is executed at the end of the loop).
Here is my implementation code directly: