Hello Devs,
In this tutorial, we will learn Laravel preg_replace_array() Function Example
The preg_replace_array function replaces a given pattern in the string sequentially using an array.
Follow this step-by-step guide below.
Example :
/**
* The attributes that are mass assignable.
*
* @var array
*/
public function index()
{
$string = 'The event will take place between :start and :end';
$replaced = preg_replace_array('/:[a-z_]+/', ['8:30', '9:00'], $string);
dd($replaced);
// Output
// The event will take place between 8:30 and 9:00
}
Output :
The event will take place between 8:30 and 9:00
May this example help you.