Say I have a number=20
and a $value=7
.
If I want to make a string of 20 7's using PHP. what's the quickest way to make this?
So output like:
$a='77777777777777777777';
Any functions to make this easier?
Common Ways to Build a StringStringBuilder builder = new StringBuilder(N); for (int i = 0; i < N; i++) { builder. append("a"); } String newString = builder. toString(); assertEquals(EXPECTED_STRING, newString);
We can easily use the Python join() function to create a string of n characters.
To define String array of specific size in Java, declare a string array and assign a new String array object to it with the size specified in the square brackets. String arrayName[] = new String[size]; //or String[] arrayName = new String[size];
String Class repeat() Method in Java with Examples The string can be repeated N number of times, and we can generate a new string that has repetitions. repeat() method is used to return String whose value is the concatenation of given String repeated count times.
$a=str_repeat($value,$number);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With