Values2keys

Converts the values of an array to the keys of it.
function values2keys($arr, $value=1){ $new = array(); while (list($k,$v) = each($arr)){ $v = trim($v); if ($v != ''){ $new[$v] = $value; } } return $new; } //Example: $array = array('a','b','c','d'); print_r(values2keys($array, 7)); /* returns: Array ( [a] => 7 [b] => 7 [c] => 7 [d] => 7 ) */

Url: http://www.jonasjohn.de/snippets/php/values2keys.htm

Language: PHP | User: ShareMySnippets | Created: Oct 16, 2013