Values2keys
Converts the values of an array to the keys of it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
)
*/
X
Url: http://www.jonasjohn.de/snippets/php/values2keys.htm
Language: PHP | User: ShareMySnippets | Created: Oct 16, 2013