3v4l.org

run code in 300+ 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:
57.94 ms | 407 KiB | 5 Q