I have a string, in PHP and the string has occurrences of the pattern %%abc%%(some substring)%%xyz%%
There are multiple occurrences of such substrings within the master string.
Each of these occurrences need to be replaced with a string from within an array
array('substring1','substring2','substring3','substring4') depending upon the response of a function() which returns back a integer between 1 to 4.
I am not able to figure out an efficient way to do this.