@ callum-macdonald.com:
I guess array_unique() should be used for that.
array_flip说明array array_flip ( array trans )
array_flip() 返回一个反转后的 array,例如
注意 如果同一个值出现了多次,则最后一个键名将作为它的值,所有其它的都丢失了。 array_flip() 如果失败返回 FALSE。
pinkgothic at gmail dot com
26-Apr-2007 08:37
In case anyone is wondering how array_flip() treats empty arrays:
http://www.callum-macdonald.com/
06-Mar-2007 06:13
It might seem obvious, but if you want to remove duplicates from an array, you can use array_flip() twice:
mikeb at tracersinfo dot com
06-Feb-2006 10:42
Further deriving on benles -> crescentfreshpot, I think the following restatement of array_invert() reads much easier and probably runs faster, too. It does yield the same results:
crescentfreshpot at yahoo dot com
03-Jul-2005 11:21
Furthering benles note, if you don't want duplicate values to overwrite existing keys but need non-duplicate values to be assigned like array_flip, use:
benles at bldigital dot com
06-Mar-2005 01:52
In case anyone wants a function that doesn't lose duplicates:
snaury at narod dot ru
23-Nov-2004 07:21
When you do array_flip, it takes the last key accurence for each value, but be aware that keys order in flipped array will be in the order, values were first seen in original array. For example, array:
znailz at yahoo dot com
05-Aug-2003 09:42
I know a lot of people want a function to remove a key by value from an array. I saw solutions that iterate(!) though the whole array comparing value by value and then unsetting that value's key. PHP has a built-in function for pretty much everything (heard it will even cook you breakfast), so if you think "wouldn't it be cool if PHP had a function to do that...", odds are it already has. Check out this example. It takes a value, gets all keys for that value if it has duplicates, unsets them all, and returns a reindexed array.
rgonzalez at kidchile dot cl
06-Mar-2003 07:58
If you need traspose an array (i.e convert columns in rows) for a multidimensional array obtain from a SQL query, try this:
| ||||