Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make string of N characters

Tags:

string

php

repeat

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?

like image 334
David19801 Avatar asked Jan 25 '12 21:01

David19801


People also ask

How do you make an n character into a string?

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);

How do you write an n character for a string in Python?

We can easily use the Python join() function to create a string of n characters.

How do you declare a string of size n in Java?

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];

How do you repeat a string for n times?

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.


1 Answers

$a=str_repeat($value,$number); 
like image 112
Eugen Rieck Avatar answered Oct 13 '22 10:10

Eugen Rieck