0

I want to make an array with the same value and set the array to be maximum based on my counter.

For example, I want to create an array with a string "hello" and I want it to keep going until the number of array is 3.

How is that possible using php with yii2 framework?

1
  • Show your efforts and return with errors. Commented Jul 26, 2016 at 2:58

2 Answers 2

1

you can use a for loop this way

$array= array();
for($i=0;$i<3;$i++){
   $array[] = "hello";
}

You will get $array with 3 hello.

Sign up to request clarification or add additional context in comments.

Comments

0

try array_fill

$count = 5;
$a = array_fill(0, $count, 'hello');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.