3v4l.org

run code in 300+ PHP versions simultaneously
<?php $sentence = '{Please|Just} make this {cool|awesome|random} test sentence {rotate {quickly|fast} and random|spin and be random}'; function sentence_spinning($str) { $new_str = preg_replace_callback('#\{([^{}]*)\}#im', function($matches) { return ($rand = array_rand($split = explode('|', $matches[1])))[$rand]; return $split[$rand]; }, $str); if ($new_str !== $str) $str = sentence_spinning($new_str); return $str; } echo sentence_spinning($sentence);

preferences:
30.46 ms | 402 KiB | 5 Q