In this article I'm presenting my solution for a very common PHP developer job interview task where it is required to create a random sentence spinning function. Input of this function is a PHP string that employs syntax telling our code where's the randomness and what are the possible substrings for each section of randomness. Basically it is required to create PHP code that's able to process strings like the following:
<?php $string = '{Please|Just} make this {cool|awesome|random} test sentence {rotate {quickly|fast} and random|spin and be random}'; ?> |
As you can probably guess the input sentence uses braces to declare sections of randomness and the pipe character to delimit substrings that should be used randomly inside their sections. Code also must be able to process nested sections of randomness.
Continue reading