I want to create an array like this [1, 1, 1, 1, 1]
In python I can use myarray = [1]*5
Is there an equivalent method in PHP or I have to add all the elements in a loop.
http://php.net/manual/en/function.array-fill.php
<?php
var_dump( array_fill( 0, 5, 1 ) );
?>
what you need is array_fill
see php array_fill
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