3v4l.org

run code in 500+ PHP versions simultaneously
<?php $str = "{three/fifteen/one hundred} this is the first random number, and this is the second, {two/four}"; echo preg_replace_callback('~\{([^{}]*)}~', function ($x) { return array_rand(array_flip(explode('/', $x[1]))); }, $str);

preferences:
44.08 ms | 779 KiB | 5 Q