$arr = array('1st', '1st');
The above $arr has 2 items , I want to repeat $arr so that it's populated with 4 items
Is there a single call in PHP?
This is a more general answer. In PHP 5.6+ you can use the "splat" operator (...) to repeat the array an arbitrary number of times:
array_merge(...array_fill(0, $n, $arr));
Where $n is any integer.
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