As far as languages with two-way relation go, there are many; perhaps
the most prototypical is Lisp, in that either member of a pair within
an alist can be used to look the pair up, with no extra function or
second map definition required.

But PHP has pretty good support, too, actually.  If you have a 1-to-1
relation, you can use array_flip() to get a second array with the keys
and values swapped in one go.  If you have a 1-to-many, as in this
case, you can use the optional search parameter to array_keys:

>>> $color = array('apple' => 'red', 'ruby' => 'red', 'banana' => 'yellow');
>>> array_keys($color, 'red')
Array
(
    [0] => apple
    [1] => ruby
)

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/



Reply via email to