I have 2 arrays one with placeholder that are keys in another array
arr1 = array(
"id" => "{{verticalId}}",
"itemPath" => "{{verticalId}}/{{pathId}}/");
arr2 = array(
"verticalId" => "value1",
"pathId" => "value2");
So how can I run on arr1
and replace placeholders with value from arr2
?
foreach ($arr1 as $key => &$value) {
$value = preg_replace_callback('/\{\{(.*?)\}\}/', function($match) use ($arr2) {
return $arr2[$match[1]];
}, $value);
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments