I am trying to use foreach statment to run through a function that preg_replaces using regular expression. Can someone help, because my method doesn’t work..
$reg_sent is an array
function reg_sent($i){
$reg_sent = "/[^A-Za-z0-9.,\n\r ]/";
return preg_replace($reg_sent, '', $i);
}
foreach($reg_sent as $key=>$value){
$value = reg_sent($value);
}
Check array_map.
This will call
reg_senton every cell of the array, and return a new array with values modified. You can replace theforeachblock you stated, with the above.