This is my code, I just want to replicate that little text through a for loop.
the result that it gives me is, Holaolalaa I don't understand why it comes out like this.
<?php
$text = "Hola";
$length = strlen($text);
for($i=0;$i<=$length;$i++){
$rest = substr($text, $i);
echo $rest;
}
?>
It comes out like this for the index of the loop. What you are doing is that it takes the text at the beginning, since the index is 0, it prints the entire word and then it removes a character from the $text variable.
If you want the word to have 4 characters and to be repeated 4 times you have to do:
If you want to print character by character do the following in the loop:
You can also use
str_split
, which creates an array with the characters of your string. Then you can go on to read that array character by character.For example:
Departure: