How to replace an array key with its value

I have the following array:

array('Elnett', 'INOA INOA', 'Playball P', 'Preferred Color Specialist', 'Série Expert', 'Série Nature', 'Techni art') 

I would like to have keys and values, for example:

 array('Elnett' => 'Elnett', 'INOA INOA' => 'INOA INOA', 'Playball P' => 'Playball', 'Preferred Color Specialis' => 'Preferred Color Specialist', 'Série Expert' => 'Série Expert', 'Série Nature' => 'Série Nature', 'Techni art' => 'Techni art') 

How can i do this?

+4
source share
4 answers
 foreach($array as $key=>$value){ $out[$value] = $value; } print_r($out); 
+2
source

There array_combine to create an array of keys / values ​​from two arrays. It should be possible to use the same array for keys and values:

 $names = array_combine($names, $names); 
+22
source

This one line answer might be helpful to someone.

 $trans = array_flip($array); 

http://us1.php.net/array_flip

array_flip returns the format value => of the key of the given array key => value. as the question has changed, this does not exactly answer the OP question.

+5
source

May do something like this. Not sure if there is a cleaner way to do this.

 foreach($names as $key => $name){ $names[$name] = $name; unset($names[$key]); } 
+1
source

All Articles