Array map

Shows how to use the array_map function.
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
function filter_val($val){
    $val = str_replace('.'''$val);
    return $val;
}
 
$a = array(
    'one'   => 'two.'
    'three' => 'four.'
    'five'  => 'six.'
);
 
$array = array_map('filter_val'$a);
print_r($array);
 
/*
returns:
 
Array
(
    [one] => two
    [three] => four
    [five] => six
)
 
*/
X

Url: http://www.jonasjohn.de/snippets/php/array-map.htm

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