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) { do { $new_str = preg_replace_callback('#\{([^{}]*)\}#im', function($matches) { $rand = array_rand($split = explode('|', $matches[1])); return $split[$rand]; }, $str, -1, $count); var_dump($count); } while ($count !== 0); return $str; } echo sentence_spinning($sentence);

preferences:
33.18 ms | 402 KiB | 5 Q