Search⌘ K
AI Features

Sequentially Replacing Substrings in a String

Explore how to use Laravel's replaceArray helper method to sequentially replace placeholder substrings in strings. Understand its application in constructing SQL queries, generating URLs, and processing user-defined templates. Gain practical experience with string replacements in both standard strings and fluent string instances.

We'll cover the following...

The replaceArray method

Applications can use the replaceArray helper method to sequentially replace placeholders in a string from an array of values.

PHP
<?php
/**
* Versions: Laravel 8, 9
*
* @return string
*/
public static function replaceArray(
string $search,
array<int|string, string> $replace,
string $subject
);

This helper method is most commonly used to construct SQL queries but can be used for any number of things, including creating URLs ...