2012-07-17 57 views
-1

我有一個數組像prods[[1,2] [3,4]],其中第一個元素(1,3)是一個product_id,第二個(2,4) - 它是數量。我需要列出所有產品及其數量。樣本從陣列元素的基地

回答

2

可以遍歷數組:

[[1,2],[3,4]].each { |product_id,qty| 
    puts "#{product_id} => #{qty}" 
} 

輸出:

1 => 2 
3 => 4