3v4l.org

run code in 500+ PHP versions simultaneously
<?php $str = 'This is just a test {#3,2,7,9} this is another test {#21,2,11}'; echo preg_replace_callback('/{[#]([\w,]{1,})}/', function ($match) { $numbers = explode(',', $match[1]); shuffle($numbers); return isset($numbers[0]) ? $numbers[0] : '{#'.$match[0].'}'; }, $str);

preferences:
44.64 ms | 653 KiB | 5 Q