preg_replace_array

The preg_replace_array function replaces a given pattern in the string sequentially using an array:
<?php $string = 'The event will take place between :start and :end';

$replaced = preg_replace_array('/:[a-z_]+/', ['8:30', '9:00'], $string);
<?php     {

        $this->assertSame(

            $expectedOutput,

            preg_replace_array($pattern, $replacements, $subject)

        );

    }

}