You can easily change using the array_walk
function together with a good regular expression.
array_walk - Apply a user supplied function to every member of an array
As the manual says, array_walk
traverses all elements of an array by applying to each of them a function provided as a parameter.
To remove the parentheses, I'll use a regular expression. The% w / w in question is simple% w / w%. Translating means "anything in parentheses that are not parentheses."
As previously reported, you need to provide a function for ER
. In this case, a function will be created as \(([^()]+)\)
. The function is as follows:
$callback = function(&$value , $key) {
preg_match('/\(([^()]+)\)/' , $value , $matches);
$value = $matches[1];
};
Applying your array with array_walk
.
array_walk($array , $callback);
You'll get the following result:
array(3) { ["chave1"]=> string(6) "valor1" ["chave2"]=> string(6) "valor2" ["chave3"]=> string(6) "valor3" }