how += in loops

hello
15 Replies
NIMA
NIMA3mo ago
for($i = 0 ; $i < $first_loop_len ; $i++){
$star_1 = "*" ;
echo $star_1; ;

}
for($i = 0 ; $i < $first_loop_len ; $i++){
$star_1 = "*" ;
echo $star_1; ;

}
why when i put echo in loop it will show 8 start and when i put echo outside loop it show only 1 star in javascript for fix the issue i do $star_1 += "*" ; but in php i cant is there any way i get like 8 start every time i call it ? not only 1
ἔρως
ἔρως3mo ago
because you can't increment an asterisk by an asterisk
NIMA
NIMA3mo ago
hmm
ἔρως
ἔρως3mo ago
you probably want to do $star .= '*'
NIMA
NIMA3mo ago
$star += '*'
ἔρως
ἔρως3mo ago
but what you REALLY want is str_repeat('*', 8)
NIMA
NIMA3mo ago
oh i dont need make for loop for this ? is this bulid in func ?
ἔρως
ἔρως3mo ago
yes
NIMA
NIMA3mo ago
oh nice is this also in js ?
ἔρως
ἔρως3mo ago
this doesn't work because it is the same as $star = (int)$star + (int)'*' which makes no sense https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat <-- '*'.repeat(8)
NIMA
NIMA3mo ago
tnx for help
ἔρως
ἔρως3mo ago
you're welcome in php, you want to do $star .= '*', by the way
NIMA
NIMA3mo ago
,
ἔρως
ἔρως3mo ago
the . is used to concatenate strings, meaning that it is the same as this: $star = $star . '*'
NIMA
NIMA3mo ago
ohh
Want results from more Discord servers?
Add your server