I have a string of 5 numbers, and I need to separate them and store them in an array. I've been trying to come up with a function to do this for hours, unsuccessfully, so I'm wondering if anyone have any ideas of accomplishing this, or if there is a build-in method to do this?
$string = "1 2 3 4 5"
Required Outcomes
$array[0] = "1 2 3 4 5" (5)
$array[1] = "1 2 3 4" (4)
$array[2] = "2 3 4 5" (4)
$array[3] = "1 2 3" (3)
$array[4] = "2 3 4" (3)
$array[5] = "3 4 5" (3)
$array[6] = "1 2" (2)
$array[7] = "2 3" (2)
$array[8] = "3 4" (2)
$array[9] = "4 5" (2)
$array[10] = "1" (1)
$array[11] = "2" (1)
$array[12] = "3" (1)
$array[13] = "4" (1)
$array[14] = "5" (1)
P.S: The example string's numbers are 5 of them, but that's just an example. The working function should work with any amount of numbers. Thank you.
Edit: I do not need a function to explode this. I already know the explode function. I'm asking for a function to get me the results below Required Outcomes no matter the amount of numbers. So if numbers are "1 2 3 4 5 6 7 8 9 10", the outcome would be like the patterns below require outcomes.
The focus should be on the patterns below required outcomes. Those patterns are the patterns that I want to get. I need a function get get those exact patterns.
More Examples
$string = "1 2 3 4"
$array[0] = "1 2 3 4"
$array[1] = "1 2 3"
$array[2] = "2 3 4"
$array[3] = "1 2"
$array[4] = "2 3"
$array[5] = "3 4"
$array[6] = "1"
$array[7] = "2"
$array[8] = "3"
$array[9] = "4"