Hash from two arrays: Difference between revisions
m
comment re indexes
m (comment re indexes) |
|||
Line 1,136:
=={{header|Phix}}==
You could of course make the values in the dictionary be indexes to valuearray instead, as shown commented out.
<lang Phix>function make_hash(sequence keyarray, sequence valuearray)
integer dict = new_dict()
for i=1 to length(keyarray) do
setd(keyarray[i],valuearray[i],dict)
-- setd(keyarray[i],i,dict)
end for
return dict
end function
constant valuearray = {"one",2,PI}
integer dict = make_hash(keyarray,valuearray)
?getd(1,dict)
?getd("two",dict)
?getd(PI,dict)
--?valuearray[getd(1,dict)]</lang>
{{out}}
<pre>
|