Lets say I have two arrays got from pre_gmatch:
preg_match_all('#<div class="cloud_flow_big">(.*?)</div>#is', $mystring, $names, PREG_SET_ORDER);
preg_match_all('#<div class="bgframe(.*?)</div></div>#is', $mystring, $numbers, PREG_SET_ORDER);
Items count in gotten arrays is always the same. So here is the code to get what is going on, and there is one repetitive word in all items of first array (this word is number in this case):
foreach ($names as $key => $name) {
$i++;
$nameclean = str_replace ("number", $numbers[$key], $names[$key]);
echo $nameclean;
}
So how to foreach first array, but in result to replace needed word in 1st array with the needed item from array 2. Example: Word number in 1st item from array $names should be replaced with first item from array $numbers (First)
You were close, here I fixed it for you:
Your error was in the str_replace(). You were making the replacement in the array $name[$key] which is only the name itself. You want to make the replacements from the $names[$key] array value.