I am trying to get a list of all substring of input. for input=a, substrings {'','a'} for input=ab, substrings {'','a','b','ab','ba'} for input=abc, substrings {'','a','b','c','ab','bc','ca','ba','cb','ac','abc','acb','bac','bca','cab','cba'} and so on.
The code I tried is here
function get_substr($string){
$array=str_split($string);
static $k=0;
for ($i=0; $i <count($array) ; $i++) {
for ($j=0; $j <count($array) ; $j++) {
$new_array[$k]=substr($string, $i, $j - $i + 1);
$k++;
}
}
return($new_array);
}
and i have o/p of this code as below
Please suggest me what changes I need or any alternative idea to do this work.