I know this is kinda weird, but I need this to complete my task.
I want to move the first two words to the two words thereafter, example is in my (error) code :
<?
$sentence = "zero one two three four five six seven eight";
$sentence2 = explode (" ",$sentence);
$total = count($sentence2);
for ($i = 4; $i < $total; ++$i) {
$result = $sentence2[2]." ".$sentence2[3]." ".$sentence2[0]." ".$sentence2[1]." ".$sentence2[$i];
}
echo "Original sentence : ".$sentence;
echo "<br>Result : ".$result;
?>
but the result from that code is not what i want, the result is
two three zero one eight
i want the result :
two three zero one four five six seven eight
can you help me make a better code?
Each time the code inside your loop runs, the
$resultvariable receives a new value.You should only append words at the end of the sequence to it.
So, replace you
forloop by this: