# Numbering array values \[multidimentional?!\]

**URL:** <https://www.ruby-forum.com/t/numbering-array-values-multidimentional/189988>\
**Category:** Ruby\
**Created:** [June 10, 2010, 11:02pm UTC](https://www.ruby-forum.com/t/numbering-array-values-multidimentional/189988 "2010-06-10T23:02:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![razta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ec9cab/32.png) [@razta](https://www.ruby-forum.com/u/razta)\
**Post date:** [June 10, 2010, 11:02pm UTC](https://www.ruby-forum.com/t/numbering-array-values-multidimentional/189988/1 "2010-06-10T23:02:26Z")

</div>

Hi,  
I’m very new to Ruby (2 days), I’m mostly used to Python/PHP/C++.

What would be ideal would be a multidimensional array however from what  
I have read Ruby does not support multidimensional arrays.

I want to be able to store data within multiple arrays and have the  
values in all of the arrays linked together.

Example;

Array1  
[vegetable]  
[fruit]

Array2  
[carrot]  
[banana]

Array3  
[tomato]  
[apple]

I want to be able to some how output;

Vegetables;  
carrot, tomato

Fruit;  
banana, apple

With a multidimensional array this would be trivial;

[vegetable][carrot]  
[vegetable][tomato]  
[fruit][banana]  
[fruit][apple]

Any help much appreciated,  
Thank you.

---

<div class="post-metadata">

**Author:** ![razta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ec9cab/32.png) [@razta](https://www.ruby-forum.com/u/razta)\
**Post date:** [June 11, 2010, 12:52am UTC](https://www.ruby-forum.com/t/numbering-array-values-multidimentional/189988/2 "2010-06-11T00:52:27Z")

</div>

On 2010-06-10 14:02:40 -0700, Safas K. said:

> [apple]
> 
> [vegetable][carrot]  
> [vegetable][tomato]  
> [fruit][banana]  
> [fruit][apple]
> 
> Any help much appreciated,  
> Thank you.

In general, multidimensional arrays are just arrays that contain arrays:

[[1,1,1],  
[2,2,2],  
[3,3,3]]

However, a Hash seems more appropriate for your specific use case:

{“vegetable” =\> [“carrot”, “tomato”],  
"fruit =\> [“banana”, “apple”]}

---

<div class="post-metadata">

**Author:** ![razta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ec9cab/32.png) [@razta](https://www.ruby-forum.com/u/razta)\
**Post date:** [June 11, 2010, 1:14am UTC](https://www.ruby-forum.com/t/numbering-array-values-multidimentional/189988/3 "2010-06-11T01:14:09Z")

</div>

Awesome! Just the thing I was looking for.

Thank you very much!
