The preg_replace_callback_array function performs a regular expression search and replaces it with a callback.
This function is supported in PHP7+ version.
mixed preg_replace_callback_array ( array $patterns_and_callbacks , mixed $subject [, int $limit = -1 [, int &$count ]] )
The function is similar to preg_replace_callback(), but it calls a callback function to perform replacements on a per-pattern match basis.
Parameter description:
$patterns_and_callbacks: associative array, key (pattern) => value (callback function)
$subject: The string or array to find and replace.
$limit: Optional, the maximum number of substitutions for each pattern, the default is -1 (no limit, all matches).
$count: optional, specifies the number of replacements.
Returns an array if subject is an array, otherwise returns a string. If an error occurs, NULL is returned.
If a match is found, the replaced target string (or string array) is returned. Otherwise, the subject will be returned unchanged.
The execution result is as follows:
6 matches for "a" found3 matches for "b" found