Re: Arbitrary mathematical relations, not just hashes

From: Date: Mon, 07 Apr 2008 01:17:19 +0000
Subject: Re: Arbitrary mathematical relations, not just hashes
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-272599@lists.php.net to get a copy of this message
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 )

« previous php.general (#272599) next »