Saturday 14 September 2013

Best way to make a bi-directional array?

Best way to make a bi-directional array?

I'm not sure if "bidirectional" is the best name for it, but I want a data
structure where both the key and the data are unique pairs. For example:
a=1,b=2,c=3... and I want to be able to call the variables in either
direction (what is the number for "a"? what is the letter for 3?). I feel
like this should be a pretty easy task, but I'm drawing a blank. The best
I can come up with is something like
array("a"=>1,1=>"a","b"=>2,2=>"b"...). There's a better way of doing this
other than storing each pair twice, right?

No comments:

Post a Comment