get all possible sentences from a string in PHP

  php, variations

I’m racking my brain how to write alghoritm in PHP that returns an array with all possible sentences
out of given string.

For example "very hard task" would produce array

"very hard"
"very task"
"hard very"
"hard task"
"task very"
"task hard"
"very hard task"
"very task hard"
"hard very task"
"hard task very"
"task very hard"
"task hard very"

It’s a sum of variations without repetition
number of possibilities is

3!/(3-1)! + 3!/(3-2)! + 3!/(3-3)! = 3 + 6 + 6 = 15

thanks in advance for any help cracking this

Source: Ask PHP