I want make from word "dsafasd".
d
s
a
f
ds
sd
dsa
asd
dsaf
fsad
dsafa
afasd
etc..
Until last word is "dsafasd".
So, the sequence will be like this in string position
0
1
2
3
01
65
012
654
0123
6543
01234
65432
etc..
Until last word is 0123456 in string location.
At first phase, it will print 1 letter from most left to middle.
At second phase, it will print 2 letters from left and right.
At third phase, it will print 3 letters from left and right.
This phase will continue until the result print the same word as word was inputted.
My Problem is I don't know to make increment from f
to ds
, sd
to dsa
and so on. I know i need 1 or more for
for length inside substr($word,$i,1)
and 2 or more if
for identify I need to stop in that length, move on to length+1 and print them in back and forth but I don't know how the criterias or the logics inside it.
Here's some thought in my mind:
$a = "dsafasd";
$b = strlen($a);
$c = ($lengthWord+1)/2;
$i=0;
$h=1;
do {
do {
echo substr($a,$i,$h),"<br>";
$i++;
} while ($i!=$c);#First Phase ends here
$h++;
$i=0;
echo substr($a,$i,$h),"<br>";
echo strrev(substr($a,$i,$h)),"<br>";
} while ($h<!=$b);
And the output becomes:
d
s
a
f
ds
sd
ds <--
sa <--
af <--
fa <--
dsa
asd
dsa <--
saf <--
afa <--
fas <--
dsaf
fasd
dsaf <--
safa <--
afas <--
fasd <--
dsafa
afasd
dsafa <--
safas <--
afasd <--
fasd <--
dsafas
safasd
dsafas <--
safasd <--
afasd <--
fasd <--
dsafasd
dsafasd <--
I can't make it stop after 2nd word was deployed and double word at last sequence. Which make words on my marks <--
shouldn't exist.