Re: Arbitrary mathematical relations, not just hashes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux