Php Preg_Replace_Callback_Array
# PHP preg_replace_callback_array() Function
[PHP Regular Expressions (PCRE)](#)
The preg_replace_callback_array function performs a regular expression search and uses a callback for replacement.
> This function is supported in PHP 7+ versions.
### Syntax
mixed preg_replace_callback_array ( array $patterns_and_callbacks , mixed $subject [, int $limit = -1 [, int &$count ]] )
This function is similar to [preg_replace_callback()](#), but it performs replacements based on callbacks for each pattern match.
Parameter Description:
* $patterns_and_callbacks: An associative array, key (pattern) => value (callback function).
* $subject: The string or array to search and replace.
* $limit: Optional, the maximum number of replacements per pattern, default is -1 (no limit, replace all matches).
* $count: Optional, specifies the number of replacements made.
### Return Value
Returns an array if subject is an array, otherwise returns a string. Returns NULL if an error occurs.
If a match is found, returns the replaced target string (or array of strings). Otherwise, the subject is returned unchanged.
### Example
## Example 1
function($match){echo strlen($match), ' matches for "a" found', PHP_EOL; }, '~+~i' =>function($match){echo strlen($match), ' matches for "b" found', PHP_EOL; }], $subject); ?>
The execution result is as follows:
6 matches for "a" found 3 matches for "b" found
[PHP Regular Expressions (PCRE)](#)
YouTip