ruby数组构造问题
伊谢尔伦
伊谢尔伦 2017-04-21 11:17:08
0
0
539

大类别中的数据循环,小类别再循环。

想构造的形势是:

c_array = [[100,200,300],[400,500],[600,700,800,900]]

这里[100,200,300]是category0的,[400,500]是category1的,[600,700,800,900]是category2的。

代码:

c_array = Array.new
co_array = Array.new
@categories.each do |c|
  c.others.each do |co|
    co_array << co.price
  end
  c_array << co_array
end
puts c_array.inspect

循环得到的结果是:

c_array = [[100,200,300,400,500,600,700,800,900],[100,200,300,400,500,600,700,800,900],[100,200,300,400,500,600,700,800,900]]

怎么循环能达到预期效果呢?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(0)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template