PHP – How to trim all values in array

Boring way:

for($i = 0; $i < count($arr); $i++){
    $arr[$i] = trim($arr[$i]);
}

The right way:

$arr = array_map('trim', $arr);

This will call function trim on every value in array $arr.

Write a Comment

Comment