i have code like this.
$str = 'A';
for ($i = 1;; $i++) {
$count = ++$str;
echo 'James said ' . $str.'<br>';
echo 'Lia said ' . $str.'<br>';
echo 'Ben said ' . $str.'<br>';
if ($str == 'D') {
echo 'STOP';
break;
}
}
die();
And give me the result like this, which is not what i wanted.
James said B
Lia said B
Ben said B
James said C
Lia said C
Ben said C
James said D
Lia said D
Ben said D
STOP
Want i want is :
James said B
Lia said C
Ben said D
STOP
How can i have a result like that? Or maybe with some other method? Like using array?
Thank you so much for the help!
You just need to increment it each time you use $str:
echo 'James said ' . ++$str . '<br>';
echo 'Lia said ' . ++$str . '<br>';
echo 'Ben said ' . ++$str . '<br>';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With