Tuesday, 23 January 2018

Array map

Shows how to use the array_map function.

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
)

*/

0 comments:

Post a Comment