Ruby on Rails
PhpArray_fill (Version #3)

Ruby



array = []

array << "value1","value2","value3"



array = ["value1","value2","value3"]

To emulate the repetition of the array_fill function, you can do something like the following, which will initialize and then fill an array.


a = []
8.times { a << "value" }

Arrays in PHP are a hybrid of hash and array. Ruby will fill in the preceding indexes with nil, unless you start from zero. If you need to start from another index, you can use the looping syntax below


a = []
(2..3).each { |i| a[i] = 'value' }

Ruby



array = []

array << "value1","value2","value3"



array = ["value1","value2","value3"]

To emulate the repetition of the array_fill function, you can do something like the following, which will initialize and then fill an array.


a = []
8.times { a << "value" }

Arrays in PHP are a hybrid of hash and array. Ruby will fill in the preceding indexes with nil, unless you start from zero. If you need to start from another index, you can use the looping syntax below


a = []
(2..3).each { |i| a[i] = 'value' }