foreach ($array as $key => $value) { $array[$key] = addslashes($value); // or whatever function you want }