how += in loops

hello
15 Replies
NIMA
NIMAOP5mo 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
ἔρως
ἔρως5mo ago
because you can't increment an asterisk by an asterisk
NIMA
NIMAOP5mo ago
hmm
ἔρως
ἔρως5mo ago
you probably want to do $star .= '*'
NIMA
NIMAOP5mo ago
$star += '*'
ἔρως
ἔρως5mo ago
but what you REALLY want is str_repeat('*', 8)
NIMA
NIMAOP5mo ago
oh i dont need make for loop for this ? is this bulid in func ?
ἔρως
ἔρως5mo ago
yes
NIMA
NIMAOP5mo ago
oh nice is this also in js ?
ἔρως
ἔρως5mo 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
NIMAOP5mo ago
tnx for help
ἔρως
ἔρως5mo ago
you're welcome in php, you want to do $star .= '*', by the way
NIMA
NIMAOP5mo ago
,
ἔρως
ἔρως5mo ago
the . is used to concatenate strings, meaning that it is the same as this: $star = $star . '*'
NIMA
NIMAOP5mo ago
ohh
Want results from more Discord servers?
Add your server