3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = 'sample {} test {} string {}'; $count = 0; echo preg_replace_callback("~{}~", function($m) use (&$count) { return '(' . $count++ . ')'; }, $string);

preferences:
27.43 ms | 404 KiB | 5 Q