3v4l.org

run code in 300+ PHP versions simultaneously
<?php function spin($string) { return preg_replace_callback('/{(?<list>[^{}]+)}/', function ($match) { $list = explode('|', $match['list']); return $list[array_rand($list)]; }, $string); } $sentence = '{Please|Just} make this {cool|awesome|random} test sentence {rotate {quickly|fast} and random|spin and be random}'; echo spin($sentence);

preferences:
36.2 ms | 402 KiB | 5 Q